function draw($extra_tools) { global $app_list_strings, $current_language, $sugar_config, $currentModule, $action, $theme; $current_module_strings = return_module_language($current_language, 'Charts'); if (isset($_REQUEST['obm_refresh'])) { $refresh = $_REQUEST['obm_refresh']; } else { $refresh = false; } $date_start = array(); $datax = array(); //get the dates to display global $current_user; $user_date_start = $current_user->getPreference('obm_date_start'); if (!empty($user_date_start) && !isset($_REQUEST['obm_date_start'])) { $date_start = $user_date_start; Log::debug("USER PREFERENCES['obm_date_start'] is:"); Log::debug($user_date_start); } elseif (isset($_REQUEST['obm_year']) && $_REQUEST['obm_year'] != '') { $date_start = $_REQUEST['obm_year'] . '-01-01'; $current_user->setPreference('obm_date_start', $date_start); Log::debug("_REQUEST['obm_date_start'] is:"); Log::debug($_REQUEST['obm_date_start']); Log::debug("_SESSION['obm_date_start'] is:"); Log::debug($current_user->getPreference('obm_date_start')); } else { $date_start = date('Y') . '-01-01'; } $user_date_end = $current_user->getPreference('obm_date_end'); if (!empty($user_date_end) && !isset($_REQUEST['obm_date_end'])) { $date_end = $user_date_end; Log::debug("USER PREFERENCES['obm_date_end'] is:"); Log::debug($date_end); } elseif (isset($_REQUEST['obm_year']) && $_REQUEST['obm_year'] != '') { $date_end = $_REQUEST['obm_year'] . '-12-31'; $current_user->setPreference('obm_date_end', $date_end); Log::debug("_REQUEST['obm_date_end'] is:"); Log::debug($_REQUEST['obm_date_end']); Log::debug("USER PREFERENCES['obm_date_end'] is:"); Log::debug($current_user->getPreference('obm_date_end')); } else { $date_end = date('Y') . '-12-31'; } $ids = array(); //get list of user ids for which to display data $user_ids = $current_user->getPreference('obm_ids'); if (!empty($user_ids) && count($user_ids) != 0 && !isset($_REQUEST['obm_ids'])) { $ids = $user_ids; Log::debug("USER PREFERENCES['obm_ids'] is:"); Log::debug($user_ids); } elseif (isset($_REQUEST['obm_ids']) && count($_REQUEST['obm_ids']) > 0) { $ids = $_REQUEST['obm_ids']; $current_user->setPreference('obm_ids', $_REQUEST['obm_ids']); Log::debug("_REQUEST['obm_ids'] is:"); Log::debug($_REQUEST['obm_ids']); Log::debug("USER PREFRENCES['obm_ids'] is:"); Log::debug($current_user->getPreference('obm_ids')); } else { $ids = get_user_array(false); $ids = array_keys($ids); } //create unique prefix based on selected users for image files $id_hash = '1'; if (isset($ids)) { sort($ids); $id_hash = crc32(implode('', $ids)); if ($id_hash < 0) { $id_hash = $id_hash * -1; } } Log::debug("ids is:"); Log::debug($ids); $id_md5 = substr(md5($current_user->id), 0, 9); // cn: format date_start|end to user's preferred global $timedate; $dateDisplayStart = strftime($timedate->get_user_date_format(), strtotime($date_start)); $dateDisplayEnd = strftime($timedate->get_user_date_format(), strtotime($date_end)); $seps = array("-", "/"); $dates = array($date_start, $date_end); $dateFileNameSafe = str_replace($seps, "_", $dates); $cache_file_name = sugar_cached("xml/") . $current_user->getUserPrivGuid() . "_outcome_by_month_" . $dateFileNameSafe[0] . "_" . $dateFileNameSafe[1] . ".xml"; Log::debug("cache file name is: {$cache_file_name}"); global $app_strings; $tools = '<div align="right"><a href="index.php?module=' . $currentModule . '&action=' . $action . '&obm_refresh=true" class="tabFormAdvLink">' . SugarThemeRegistry::current()->getImage('refresh', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_REFRESH']) . ' ' . $current_module_strings['LBL_REFRESH'] . '</a> <a href="javascript: toggleDisplay(\'outcome_by_month_edit\');" class="tabFormAdvLink">' . SugarThemeRegistry::current()->getImage('edit', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_EDIT']) . ' ' . $current_module_strings['LBL_EDIT'] . '</a> ' . $extra_tools . '</div>'; ?> <?php echo '<span onmouseover="this.style.cursor=\'move\'" id="chart_handle_' . $this->order . '">' . get_form_header($current_module_strings['LBL_YEAR_BY_OUTCOME'], $tools, false) . '</span>'; ?> <?php $cal_lang = "en"; $cal_dateformat = parse_calendardate($app_strings['NTC_DATE_FORMAT']); if (empty($_SESSION['obm_ids'])) { $_SESSION['obm_ids'] = ""; } ?> <p> <div id='outcome_by_month_edit' style='display: none;'> <form name="outcome_by_month" action="index.php" method="post" > <input type="hidden" name="module" value="<?php echo $currentModule; ?> "> <input type="hidden" name="action" value="<?php echo $action; ?> "> <input type="hidden" name="obm_refresh" value="true"> <input type="hidden" name="obm_date_start" value="<?php if (isset($_SESSION['obm_date_start'])) { echo $_SESSION['obm_date_start']; } ?> "> <input type="hidden" name="obm_date_end" value="<?php if (isset($_SESSION['obm_date_end'])) { echo $_SESSION['obm_date_end']; } ?> "> <table cellpadding="0" cellspacing="0" border="0" class="edit view" align="center"> <tr> <td valign='top' nowrap ><b><?php echo $current_module_strings['LBL_YEAR']; ?> </b><br><span class="dateFormat"><?php echo $app_strings['NTC_YEAR_FORMAT']; ?> </span></td> <td valign='top' ><input class="text" name="obm_year" size='12' maxlength='10' id='obm_year' value='<?php if (isset($date_start)) { echo substr($date_start, 0, 4); } ?> '> </td> <td valign='top'><b><?php echo $current_module_strings['LBL_USERS']; ?> </b></td> <td valign='top'><select name="obm_ids[]" multiple size='3'><?php echo get_select_options_with_id(get_user_array(false), $ids); ?> </select></td> <td align="right" valign="top"><input class="button" onclick="return verify_chart_data_outcome_by_month();" type="submit" title="<?php echo $app_strings['LBL_SELECT_BUTTON_TITLE']; ?> " value="<?php echo $app_strings['LBL_SELECT_BUTTON_LABEL']; ?> " /><input class="button" onClick="javascript: toggleDisplay('outcome_by_month_edit');" type="button" title="<?php echo $app_strings['LBL_CANCEL_BUTTON_TITLE']; ?> " accessKey="<?php echo $app_strings['LBL_CANCEL_BUTTON_KEY']; ?> " value="<?php echo $app_strings['LBL_CANCEL_BUTTON_LABEL']; ?> "/></td> </tr> </table> </form> </div> </p> <?php // draw chart echo "<p align='center'>" . $this->gen_xml($date_start, $date_end, $ids, $cache_file_name, $refresh, $current_module_strings) . "</p>"; echo "<P align='center'><span class='chartFootnote'>" . $current_module_strings['LBL_MONTH_BY_OUTCOME_DESC'] . "</span></P>"; ?> <?php if (file_exists($cache_file_name)) { $file_date = $timedate->asUser($timedate->fromTimestamp(filemtime($cache_file_name))); } else { $file_date = ''; } ?> <span class='chartFootnote'> <p align="right"><i><?php echo $current_module_strings['LBL_CREATED_ON'] . ' ' . $file_date; ?> </i></p> </span> <?php echo get_validate_chart_js(); }
function draw($extra_tools) { global $action; global $app_list_strings; global $app_strings; global $current_language; global $current_user; global $currentModule; global $sugar_config; global $theme; global $timedate; $user_dateFormat = $timedate->get_date_format(); $current_module_strings = return_module_language($current_language, 'Charts'); if (isset($_REQUEST['pbss_refresh'])) { $refresh = $_REQUEST['pbss_refresh']; } else { $refresh = false; } //get the dates to display $user_date_start = $current_user->getPreference('pbss_date_start'); if (!empty($user_date_start) && !isset($_REQUEST['pbss_date_start'])) { $date_start = $timedate->to_display_date($user_date_start, false); Log::debug("USER PREFERENCES['pbss_date_start'] is:"); Log::debug($user_date_start); } elseif (isset($_REQUEST['pbss_date_start']) && $_REQUEST['pbss_date_start'] != '') { $date_start = $_REQUEST['pbss_date_start']; $ds = $timedate->to_db_date($date_start, false); $current_user->setPreference('pbss_date_start', $ds); Log::debug("_REQUEST['pbss_date_start'] is:"); Log::debug($_REQUEST['pbss_date_start']); Log::debug("USER PREFERENCES['pbss_date_start'] is:"); Log::debug($current_user->getPreference('pbss_date_start')); } else { $date_start = $timedate->nowDate(); } $user_date_end = $current_user->getPreference('pbss_date_end'); if (!empty($user_date_end) && !isset($_REQUEST['pbss_date_end'])) { $date_end = $timedate->to_display_date($user_date_end, false); Log::debug("USER PREFERENCES['pbss_date_end'] is:"); Log::debug($user_date_end); } elseif (isset($_REQUEST['pbss_date_end']) && $_REQUEST['pbss_date_end'] != '') { $date_end = $_REQUEST['pbss_date_end']; $de = $timedate->to_db_date($date_end, false); $current_user->setPreference('pbss_date_end', $de); Log::debug("_REQUEST['pbss_date_end'] is:"); Log::debug($_REQUEST['pbss_date_end']); Log::debug("USER PREFERENCES['pbss_date_end'] is:"); Log::debug($current_user->getPreference('pbss_date_end')); } else { $date_end = $timedate->asUserDate($timedate->fromString("2010-01-01")); Log::debug("USER PREFERENCES['pbss_date_end'] not found. Using: " . $date_end); } // cn: format date_start|end to user's preferred $dateDisplayStart = strftime($timedate->get_user_date_format(), strtotime($date_start)); $dateDisplayEnd = strftime($timedate->get_user_date_format(), strtotime($date_end)); $seps = array("-", "/"); $dates = array($date_start, $date_end); $dateFileNameSafe = str_replace($seps, "_", $dates); $dateXml[0] = $timedate->swap_formats($date_start, $user_dateFormat, $timedate->dbDayFormat); $dateXml[1] = $timedate->swap_formats($date_end, $user_dateFormat, $timedate->dbDayFormat); $tempx = array(); $datax = array(); $datax_selected = array(); $user_tempx = $current_user->getPreference('pbss_sales_stages'); //get list of sales stage keys to display if (!empty($user_tempx) && count($user_tempx) > 0 && !isset($_REQUEST['pbss_sales_stages'])) { $tempx = $user_tempx; Log::debug("USER PREFERENCES['pbss_sales_stages'] is:"); Log::debug($user_tempx); } elseif (isset($_REQUEST['pbss_sales_stages']) && count($_REQUEST['pbss_sales_stages']) > 0) { $tempx = $_REQUEST['pbss_sales_stages']; $current_user->setPreference('pbss_sales_stages', $_REQUEST['pbss_sales_stages']); Log::debug("_REQUEST['pbss_sales_stages'] is:"); Log::debug($_REQUEST['pbss_sales_stages']); Log::debug("USER PREFERENCES['pbss_sales_stages'] is:"); Log::debug($current_user->getPreference('pbss_sales_stages')); } //set $datax using selected sales stage keys if (count($tempx) > 0) { foreach ($tempx as $key) { $datax[$key] = $app_list_strings['sales_stage_dom'][$key]; array_push($datax_selected, $key); } } else { $datax = $app_list_strings['sales_stage_dom']; $datax_selected = array_keys($app_list_strings['sales_stage_dom']); } Log::debug("datax is:"); Log::debug($datax); $ids = array(); $new_ids = array(); $user_ids = $current_user->getPreference('pbss_ids'); //get list of user ids for which to display data if (!empty($user_ids) && count($user_ids) != 0 && !isset($_REQUEST['pbss_ids'])) { $ids = $user_ids; Log::debug("USER PREFERENCES['pbss_ids'] is:"); Log::debug($user_ids); } elseif (isset($_REQUEST['pbss_ids']) && count($_REQUEST['pbss_ids']) > 0) { $ids = $_REQUEST['pbss_ids']; $current_user->setPreference('pbss_ids', $_REQUEST['pbss_ids']); Log::debug("_REQUEST['pbss_ids'] is:"); Log::debug($_REQUEST['pbss_ids']); Log::debug("USER PREFERENCES['pbss_ids'] is:"); Log::debug($current_user->getPreference('pbss_ids')); } else { $ids = get_user_array(false); $ids = array_keys($ids); } //create unique prefix based on selected users for image files $id_hash = '1'; if (isset($ids)) { sort($ids); $id_hash = crc32(implode('', $ids)); if ($id_hash < 0) { $id_hash = $id_hash * -1; } } Log::debug("ids is:"); Log::debug($ids); $cache_file_name = sugar_cached("xml/") . $current_user->getUserPrivGuid() . "_lead_source_by_outcome_" . $dateFileNameSafe[0] . "_" . $dateFileNameSafe[1] . ".xml"; Log::debug("cache file name is: {$cache_file_name}"); $tools = '<div align="right"><a href="index.php?module=' . $currentModule . '&action=' . $action . '&pbss_refresh=true" class="tabFormAdvLink">' . SugarThemeRegistry::current()->getImage('refresh', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_REFRESH']) . ' ' . $current_module_strings['LBL_REFRESH'] . '</a> <a href="javascript: toggleDisplay(\'pipeline_by_sales_stage_edit\');" class="tabFormAdvLink">' . SugarThemeRegistry::current()->getImage('edit', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_EDIT']) . ' ' . $current_module_strings['LBL_EDIT'] . '</a> ' . $extra_tools . '</div>'; echo '<span onmouseover="this.style.cursor=\'move\'" id="chart_handle_' . $this->order . '">' . get_form_header($current_module_strings['LBL_SALES_STAGE_FORM_TITLE'], $tools, false) . '</span>'; ?> <?php $cal_lang = "en"; $cal_dateformat = $timedate->get_cal_date_format(); if (empty($_SESSION['pbss_sales_stages'])) { $_SESSION['pbss_sales_stages'] = ""; } if (empty($_SESSION['pbss_ids'])) { $_SESSION['pbss_ids'] = ""; } // set populate values $puser_date_start = $current_user->getPreference('user_date_start'); ?> <p> <div id='pipeline_by_sales_stage_edit' style='display: none;'> <form name='pipeline_by_sales_stage' action="index.php" method="post" > <input type="hidden" name="module" value="<?php echo $currentModule; ?> "> <input type="hidden" name="action" value="<?php echo $action; ?> "> <input type="hidden" name="pbss_refresh" value="true"> <table cellpadding="0" cellspacing="0" border="0" class="edit view" align="center"> <tr> <td valign='top' nowrap><b><?php echo $current_module_strings['LBL_DATE_START']; ?> </b> <br><span class="dateFormat"><?php echo "(" . $timedate->get_user_date_format() . ")"; ?> </span></td> <td valign='top' ><input class="text" name="pbss_date_start" size='12' maxlength='10' id='date_start' value='<?php if (isset($date_start)) { echo $date_start; } ?> '> <?php echo SugarThemeRegistry::current()->getImage('jscalendar', 'id="date_start_trigger" align="absmiddle"', null, null, ".gif", $app_strings['LBL_ENTER_DATE']); ?> </td> </tr> <tr> <td valign='top' nowrap><b><?php echo $current_module_strings['LBL_DATE_END']; ?> </b><br><span class="dateFormat"><?php echo "(" . $timedate->get_user_date_format() . ")"; ?> </span></td> <td valign='top' ><input class="text" name="pbss_date_end" size='12' maxlength='10' id='date_end' value='<?php if (isset($date_end)) { echo $date_end; } ?> '> <?php echo SugarThemeRegistry::current()->getImage('jscalendar', 'id="date_end_trigger" align="absmiddle"', null, null, ".gif", $app_strings['LBL_ENTER_DATE']); ?> </td> </tr> <tr> <td valign='top' nowrap><b><?php echo $current_module_strings['LBL_SALES_STAGES']; ?> </b></td> <td valign='top' ><select name="pbss_sales_stages[]" multiple size='3'><?php echo get_select_options_with_id($app_list_strings['sales_stage_dom'], $datax_selected); ?> </select></td> </tr> <tr> <td valign='top' nowrap><b><?php echo $current_module_strings['LBL_USERS']; ?> </b></td> <td valign='top' ><select name="pbss_ids[]" multiple size='3'><?php echo get_select_options_with_id(get_user_array(false), $ids); ?> </select></td> </tr> <tr> <?php global $app_strings; ?> <td align="right" colspan="2"><input class="button" onclick="return verify_chart_data(pipeline_by_sales_stage);" type="submit" title="<?php echo $app_strings['LBL_SELECT_BUTTON_TITLE']; ?> " value="<?php echo $app_strings['LBL_SELECT_BUTTON_LABEL']; ?> " /><input class="button" onClick="javascript: toggleDisplay('pipeline_by_sales_stage_edit');" type="button" title="<?php echo $app_strings['LBL_CANCEL_BUTTON_TITLE']; ?> " accessKey="<?php echo $app_strings['LBL_CANCEL_BUTTON_KEY']; ?> " value="<?php echo $app_strings['LBL_CANCEL_BUTTON_LABEL']; ?> "/></td> </tr> </table> </form> <script type="text/javascript"> Calendar.setup ({ inputField : "date_start", ifFormat : "<?php echo $cal_dateformat; ?> ", showsTime : false, button : "date_start_trigger", singleClick : true, step : 1, weekNumbers:false }); Calendar.setup ({ inputField : "date_end", ifFormat : "<?php echo $cal_dateformat; ?> ", showsTime : false, button : "date_end_trigger", singleClick : true, step : 1, weekNumbers:false }); </script> </div> </p> <?php // draw table echo "<P align='center'>" . $this->gen_xml($datax, $dateXml[0], $dateXml[1], $ids, $cache_file_name, $refresh, 'hBarF', $current_module_strings) . "</P>"; echo "<P align='center'><span class='chartFootnote'>" . $current_module_strings['LBL_SALES_STAGE_FORM_DESC'] . "</span></P>"; if (file_exists($cache_file_name)) { $file_date = $timedate->asUser($timedate->fromTimestamp(filemtime($cache_file_name))); } else { $file_date = ''; } ?> <span class='chartFootnote'> <p align="right"><i><?php echo $current_module_strings['LBL_CREATED_ON'] . ' ' . $file_date; ?> </i></p> </span> <?php echo get_validate_chart_js(); }
echo "<P align='center'><span class='chartFootnote'>" . $current_module_strings['LBL_PIPELINE_FORM_TITLE_DESC'] . "</span></P>"; if (file_exists($cache_file_name)) { $file_date = $timedate->asUser($timedate->fromTimestamp(filemtime($cache_file_name))); } else { $file_date = ''; } ?> <span class='chartFootnote'> <p align="right"><i><?php echo $current_module_strings['LBL_CREATED_ON'] . ' ' . $file_date; ?> </i></p> </span> <?php echo get_validate_chart_js(); /** * Creates opportunity pipeline image as a HORIZONTAL accumlated BAR GRAPH for multiple users. * param $datax- the sales stage data to display in the x-axis * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. * All Rights Reserved.. * Contributor(s): ______________________________________.. */ function gen_xml_pipeline_by_sales_stage($datax = array('foo', 'bar'), $date_start = '2071-10-15', $date_end = '2071-10-15', $user_id = array('1'), $cache_file_name = 'a_file', $refresh = false, $chart_size = 'hBarF', $current_module_strings) { global $app_strings, $charset, $lang, $barChartColors, $current_user; $kDelim = $current_user->getPreference('num_grp_sep'); global $timedate; if (!file_exists($cache_file_name) || $refresh == true) { $GLOBALS['log']->debug("starting pipeline chart"); $GLOBALS['log']->debug("datax is:");
function display() { global $app_list_strings, $current_language, $sugar_config, $currentModule, $action, $current_user, $theme, $timedate, $image_path; $this->loadLanguage('MyPipelineBySalesStageDashlet', 'modules/Charts/Dashlets/'); $returnStr = ''; $user_dateFormat = $timedate->get_date_format(); $current_module_strings = return_module_language($current_language, 'Charts'); if (isset($_REQUEST['mypbss_refresh'])) { $refresh = $_REQUEST['mypbss_refresh']; } else { $refresh = false; } $date_start = $this->mypbss_date_start; $date_end = $this->mypbss_date_end; // cn: format date_start|end to user's preferred $dateStartDisplay = strftime($timedate->get_user_date_format(), strtotime($date_start)); $dateEndDisplay = strftime($timedate->get_user_date_format(), strtotime($date_end)); $seps = array("-", "/"); $dates = array($date_start, $date_end); $dateFileNameSafe = str_replace($seps, "_", $dates); $dateXml[0] = $timedate->swap_formats($date_start, $user_dateFormat, $timedate->dbDayFormat); $dateXml[1] = $timedate->swap_formats($date_end, $user_dateFormat, $timedate->dbDayFormat); $datax = array(); $selected_datax = array(); //get list of sales stage keys to display $user_sales_stage = $this->mypbss_sales_stages; $tempx = $user_sales_stage; //set $datax using selected sales stage keys if (count($tempx) > 0) { foreach ($tempx as $key) { $datax[$key] = $app_list_strings['sales_stage_dom'][$key]; array_push($selected_datax, $key); } } else { $datax = $app_list_strings['sales_stage_dom']; $selected_datax = array_keys($app_list_strings['sales_stage_dom']); } $GLOBALS['log']->debug("datax is:"); $GLOBALS['log']->debug($datax); $ids = array($current_user->id); //create unique prefix based on selected users for image files $id_hash = '1'; if (isset($ids)) { sort($ids); $id_hash = crc32(implode('', $ids)); if ($id_hash < 0) { $id_hash = $id_hash * -1; } } $GLOBALS['log']->debug("ids is:"); $GLOBALS['log']->debug($ids); $id_md5 = substr(md5($current_user->id), 0, 9); $seps = array("-", "/"); $dates = array($dateStartDisplay, $dateEndDisplay); $dateFileNameSafe = str_replace($seps, "_", $dates); $cache_file_name = $current_user->getUserPrivGuid() . "_" . $theme . "_my_pipeline_" . $dateFileNameSafe[0] . "_" . $dateFileNameSafe[1] . ".xml"; $GLOBALS['log']->debug("cache file name is: {$cache_file_name}"); // echo get_form_header($mod_strings['LBL_PIPELINE_FORM_TITLE'], $tools , false); $returnStr .= "<p align='center'>" . $this->gen_xml_pipeline_by_sales_stage($datax, $dateXml[0], $dateXml[1], $ids, $sugar_config['tmp_dir'] . $cache_file_name, $refresh, 'hBarS', $current_module_strings) . "</p>"; $returnStr .= "<P align='center'><span class='chartFootnote'>" . $current_module_strings['LBL_PIPELINE_FORM_TITLE_DESC'] . "</span></P>"; if (file_exists($sugar_config['tmp_dir'] . $cache_file_name)) { $file_date = date($timedate->get_date_format() . " " . $timedate->get_time_format(), filemtime($sugar_config['tmp_dir'] . $cache_file_name)); } else { $file_date = ''; } $returnStr .= "<span class='chartFootnote'>\n <p align='right'><i>{$current_module_strings['LBL_CREATED_ON']} {$file_date}</i></p>\n </span>"; $returnStr .= get_validate_chart_js(); return parent::display('<div align="center"><a href="#" onclick="SUGAR.sugarHome.retrieveDashlet(\'' . $this->id . '\', \'index.php?action=DisplayDashlet&module=Home&to_pdf=1&mypbss_refresh=true&id=' . $this->id . '\'); return false"; class="chartToolsLink">' . $this->dashletStrings['LBL_REFRESH'] . '</a></div>') . $returnStr; }