<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rock, Paper, Software &#187; SugarCRM</title>
	<atom:link href="http://software.tulentsev.com/category/web-development/sugarcrm-web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://software.tulentsev.com</link>
	<description>Random thoughts about programming</description>
	<lastBuildDate>Fri, 03 Feb 2012 13:47:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SugarCRM: More colors!</title>
		<link>http://software.tulentsev.com/2009/02/sugarcrm-more-colors/</link>
		<comments>http://software.tulentsev.com/2009/02/sugarcrm-more-colors/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 18:24:41 +0000</pubDate>
		<dc:creator>Sergei Tulentsev</dc:creator>
				<category><![CDATA[SugarCRM]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[Calendar]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://software.tulentsev.com/?p=120</guid>
		<description><![CDATA[When I was implementing previous issue, my manager asked me: &#8220;Can we also mark meetings with colors, corresponding to users?&#8221;. This way it becomes somewhat easier to identify originator of an event. &#8220;Yeah, it would be cool, but it can be tricky and difficult to implement&#8221;,  I said, rejecting the feature request. I said so [...]]]></description>
			<content:encoded><![CDATA[<p>When I was implementing <a title="SugarCRM: Really shared calendar" href="http://software.tulentsev.com/2009/02/sugarcrm-really-shared-calendar/">previous issue</a>, my manager asked me: &#8220;Can we also mark meetings with colors, corresponding to users?&#8221;. This way it becomes somewhat easier to identify originator of an event. &#8220;Yeah, it would be cool, but it can be tricky and difficult to implement&#8221;,  I said, rejecting the feature request. I said so just to save my ass from potentially frustrating project. Just the day before Marcelo had told me that he has a friend who was working with SugarCRM for a year and he hadn&#8217;t quite enjoyed the experience.<span id="more-120"></span></p>
<p>But later at home I was thinking about it and decided that it may not be as hard as it looks. We can divide the task into two subtasks:</p>
<ul>
<li>provide a unique color for each user</li>
<li>use this color when generating markup for an event</li>
</ul>
<p>The latter subtask was quite easy to implement, I already knew a place where the markup was generated. I was more scared by the former one. If done in &#8220;enterprisey&#8221; way, it could involve new property in User entity, new configuration screens, database alterations, etc. But there is a solution almost as good as abovementioned and much more simple. Let&#8217;s define a function that maps user name to color. md5() is a good candidate :-)</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_color_by_name<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$html_color_string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$html_color_string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I also used RGB&lt;=&gt;HSV transformation functions, because I wanted to get lighter colors. Initially I wanted to highlight event&#8217;s name with the color, but it turned out that text is not always readable. I decided not to write functions that calculate good contrasting colors and put a small color rectangle instead of highlight. This rectangle is essentially a span with several &amp;nbsp; &#8216;s as a body.</p>
<p>So, final result looks like this:<a href="http://software.tulentsev.com/wp-content/uploads/2009/02/sugar_colors.png"><img class="aligncenter size-full wp-image-123" title="sugar_colors" src="http://software.tulentsev.com/wp-content/uploads/2009/02/sugar_colors.png" alt="sugar_colors" width="577" height="616" /></a></p>
<p>Here is <a title="colors.patch" href="http://software.tulentsev.com/wp-content/uploads/2009/02/colors.patch">complete patch</a> (it has too big lines to look good on this page)</p>
]]></content:encoded>
			<wfw:commentRss>http://software.tulentsev.com/2009/02/sugarcrm-more-colors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SugarCRM: really shared calendar</title>
		<link>http://software.tulentsev.com/2009/02/sugarcrm-really-shared-calendar/</link>
		<comments>http://software.tulentsev.com/2009/02/sugarcrm-really-shared-calendar/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 17:42:04 +0000</pubDate>
		<dc:creator>Sergei Tulentsev</dc:creator>
				<category><![CDATA[SugarCRM]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[Calendar]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Shared]]></category>

		<guid isPermaLink="false">http://software.tulentsev.com/?p=108</guid>
		<description><![CDATA[SugarCRM is a decent piece of software. At least, it doesn&#8217;t look bad and source code is not as scary as it could be. However, it could have better documentation (I realized that when I was adding some custom fields to built-in entities). But this is another topic. And today I am going to tell [...]]]></description>
			<content:encoded><![CDATA[<p>SugarCRM is a decent piece of software. At least, it doesn&#8217;t look bad and source code is not as scary as it could be. However, it could have better documentation (I realized that when I was adding some custom fields to built-in entities). But this is another topic.</p>
<p>And today I am going to tell you about its Calendar feature. My colleagues were wishing it could be easier to share a meeting with others. Yes, sharing is theoretically (and practically) possible. All you have to do is to add selected individuals to your event and they will see it on their calendars in &#8220;Shared&#8221; section. This sounds like sensible behavior for large companies. However, for a small company like us it is more desirable to have zero-friction sharing. It will bring some informational noise (meetings that don&#8217;t really relate to certain individuals), but since we are small company, we can live with it.  So, I started looking into the sources and here are my findings. SugarCRM stores association between users and meetings (and other entities, like calls) in join tables, usually named like &#8220;meetings_users&#8221;. And it uses these tables, when showing calendar. The easiest solution for our problem (zero friction sharing) would be to take that join table out of queries and show ALL meetings. And we will do just that.<span id="more-108"></span></p>
<p>Go into &lt;sugarcrm_path&gt;/include/utils/activity_utils.php. In the beginning of the file there will be a function <em>build_related_list_by_user_id</em>. It is used by all calendar routines to extract related events. Find strings:</p>
<div style="overflow: auto;">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT <span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span>.* from <span style="color: #006699; font-weight: bold;">{$bean-&gt;rel_users_table}</span>,<span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span> &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$auto_where</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; <span style="color: #006699; font-weight: bold;">{$bean-&gt;rel_users_table}</span>.<span style="color: #006699; font-weight: bold;">{$bean_id_name}</span>=<span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span>.id AND <span style="color: #006699; font-weight: bold;">{$bean-&gt;rel_users_table}</span>.user_id='<span style="color: #006699; font-weight: bold;">{$user_id}</span>' AND <span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span>.deleted=0 AND <span style="color: #006699; font-weight: bold;">{$bean-&gt;rel_users_table}</span>.deleted=0&quot;</span><span style="color: #339933;">;</span></pre></div></div>

</div>
<p>And replace them with something like this:</p>
<div style="overflow: auto;">

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$auto_where</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' WHERE '</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$where</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$auto_where</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$where</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">' AND '</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Use a simpler query in case of meetings.</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$bean</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table_name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;meetings&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> “SELECT <span style="color: #009900;">&#123;</span><span style="color: #000088;">$bean</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table_name</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">.*</span> from <span style="color: #009900;">&#123;</span><span style="color: #000088;">$bean</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rel_users_table</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$bean</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">table_name</span><span style="color: #009900;">&#125;</span> “<span style="color: #339933;">;</span>
    <span style="color: #000088;">$auto_where</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; <span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span>.deleted=0 &quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT <span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span>.* from <span style="color: #006699; font-weight: bold;">{$bean-&gt;rel_users_table}</span>,<span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span> &quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$auto_where</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; <span style="color: #006699; font-weight: bold;">{$bean-&gt;rel_users_table}</span>.<span style="color: #006699; font-weight: bold;">{$bean_id_name}</span>=<span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span>.id AND <span style="color: #006699; font-weight: bold;">{$bean-&gt;rel_users_table}</span>.user_id='<span style="color: #006699; font-weight: bold;">{$user_id}</span>' AND <span style="color: #006699; font-weight: bold;">{$bean-&gt;table_name}</span>.deleted=0 AND <span style="color: #006699; font-weight: bold;">{$bean-&gt;rel_users_table}</span>.deleted=0&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</div>
<p>Voila! Thas was easy, wasn&#8217;t it? </p>
]]></content:encoded>
			<wfw:commentRss>http://software.tulentsev.com/2009/02/sugarcrm-really-shared-calendar/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

