/** function used to get the top 5 quotes from the ListView query * @return array $values - array with the title, header and entries like Array('Title'=>$title,'Header'=>$listview_header,'Entries'=>$listview_entries) where as listview_header and listview_entries are arrays of header and entity values which are returned from function getListViewHeader and getListViewEntries */ function getTopQuotes($maxval, $calCnt) { require_once "data/Tracker.php"; require_once 'modules/Quotes/Quotes.php'; require_once 'include/logging.php'; require_once 'include/ListView/ListView.php'; require_once 'include/utils/utils.php'; require_once 'modules/CustomView/CustomView.php'; global $app_strings, $current_language, $current_user; $current_module_strings = return_module_language($current_language, 'Quotes'); global $list_max_entries_per_page, $adb, $theme, $mod_strings; $log = LoggerManager::getLogger('quote_list'); $url_string = ''; $sorder = ''; $oCustomView = new CustomView("Quotes"); $customviewcombo_html = $oCustomView->getCustomViewCombo(); if (isset($_REQUEST['viewname']) == false || $_REQUEST['viewname'] == '') { if ($oCustomView->setdefaultviewid != "") { $viewid = $oCustomView->setdefaultviewid; } else { $viewid = "0"; } } $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; //Retreive the list from Database //<<<<<<<<<customview>>>>>>>>> $date_var = date('Y-m-d'); $currentModule = 'Quotes'; $viewId = getCvIdOfAll($currentModule); $queryGenerator = new QueryGenerator($currentModule, $current_user); $queryGenerator->initForCustomViewById($viewId); $meta = $queryGenerator->getMeta($currentModule); $accessibleFieldNameList = array_keys($meta->getModuleFields()); $customViewFields = $queryGenerator->getCustomViewFields(); $fields = $queryGenerator->getFields(); $newFields = array_diff($fields, $customViewFields); $widgetFieldsList = array('subject', 'potential_id', 'account_id', 'total'); $widgetFieldsList = array_intersect($accessibleFieldNameList, $widgetFieldsList); $widgetSelectedFields = array_chunk(array_intersect($customViewFields, $widgetFieldsList), 2); //select the first chunk of two fields $widgetSelectedFields = $widgetSelectedFields[0]; if (count($widgetSelectedFields) < 2) { $widgetSelectedFields = array_chunk(array_merge($widgetSelectedFields, $accessibleFieldNameList), 2); //select the first chunk of two fields $widgetSelectedFields = $widgetSelectedFields[0]; } $newFields = array_merge($newFields, $widgetSelectedFields); $queryGenerator->setFields($newFields); $_REQUEST = getTopQuotesSearch($_REQUEST, array('assigned_user_id' => $current_user->column_fields['user_name'], 'validtill' => $date_var, 'quotestage.Rejected' => $current_module_strings['Rejected'], 'quotestage.Accepted' => $current_module_strings['Accepted'])); $queryGenerator->addUserSearchConditions($_REQUEST); $search_qry = '&query=true' . getSearchURL($_REQUEST); $query = $queryGenerator->getQuery(); //<<<<<<<<customview>>>>>>>>> $query .= " LIMIT " . $adb->sql_escape_string($maxval); if ($calCnt == 'calculateCnt') { $list_result_rows = $adb->query(mkCountQuery($query)); return $adb->query_result($list_result_rows, 0, 'count'); } $list_result = $adb->query($query); //Retreiving the no of rows $noofrows = $adb->num_rows($list_result); //Retreiving the start value from request if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') { $start = vtlib_purify($_REQUEST['start']); } else { $start = 1; } //Retreive the Navigation array $navigation_array = getNavigationValues($start, $noofrows, $list_max_entries_per_page); if ($navigation_array['start'] == 1) { if ($noofrows != 0) { $start_rec = $navigation_array['start']; } else { $start_rec = 0; } if ($noofrows > $list_max_entries_per_page) { $end_rec = $navigation_array['start'] + $list_max_entries_per_page - 1; } else { $end_rec = $noofrows; } } else { if ($navigation_array['next'] > $list_max_entries_per_page) { $start_rec = $navigation_array['next'] - $list_max_entries_per_page; $end_rec = $navigation_array['next'] - 1; } else { $start_rec = $navigation_array['prev'] + $list_max_entries_per_page; $end_rec = $noofrows; } } $focus = new Quotes(); $title = array('TopOpenQuotes.gif', $current_module_strings['LBL_MY_TOP_QUOTE'], 'home_mytopquote'); //Retreive the List View Table Header $controller = new ListViewController($adb, $current_user, $queryGenerator); $controller->setHeaderSorting(false); $header = $controller->getListViewHeader($focus, $currentModule, $url_string, $sorder, $order_by, true); $entries = $controller->getListViewEntries($focus, $currentModule, $list_result, $navigation_array, true); $values = array('ModuleName' => 'Quotes', 'Title' => $title, 'Header' => $header, 'Entries' => $entries, 'search_qry' => $search_qry); if ($display_empty_home_blocks && $noofrows == 0 || $noofrows > 0) { return $values; } }
function module_Chart($user_id, $date_start = "2000-01-01", $end_date = "2017-01-01", $query, $graph_for, $title, $added_qry = "", $module = "", $graph_type) { global $adb, $current_user, $mod_strings, $default_charset; global $days, $date_array, $period_type; if ($added_qry != "") { $query .= $added_qry; } $result = $adb->query($query); $no_of_rows = $adb->num_rows($result); $mod_count_array = array(); $search_str_array = array(); $mod_name_array = array(); $count_by_date[] = array(); $mod_tot_cnt_array = array(); $mod_name_val = ""; $mod_cnt_crtd_date = ""; $target_val = ""; $bar_target_val = ""; $test_target_val = ""; if ($no_of_rows != 0) { while ($row = $adb->fetch_array($result)) { if ($graph_for == 'sostatus' || $graph_for == 'leadsource' || $graph_for == 'leadstatus' || $graph_for == 'industry' || $graph_for == 'productcategory' || $graph_for == 'postatus' || $graph_for == 'invoicestatus' || $graph_for == 'ticketstatus' || $graph_for == 'priority' || $graph_for == 'category' || $graph_for == 'quotestage' || $graph_for == 'salesstage') { $mod_name = getTranslatedString($row[$graph_for]); $search_str = $row[$graph_for]; } else { $mod_name = $row[$graph_for]; $search_str = $row[$graph_for]; } if ($mod_name == "") { $mod_name = $mod_strings["Un Assigned"]; $search_str = " "; } $crtd_time = $row['createdtime']; $crtd_time_array = explode(" ", $crtd_time); $crtd_date = $crtd_time_array[0]; if (!isset($mod_tot_cnt_array[$crtd_date])) { $mod_tot_cnt_array[$crtd_date] = 0; } $mod_tot_cnt_array[$crtd_date] += 1; if (in_array($mod_name, $mod_name_array) == false) { $uniqueid[$mod_name] = '0'; array_push($mod_name_array, $mod_name); // getting all the unique Names into the array if ($graph_for == "productname") { if ($row['qtyinstock'] == '') { $mod_count_array[$mod_name] = 1; } else { $mod_count_array[$mod_name] = $row['qtyinstock']; } } } else { if ($graph_for == "productname") { $uniqueid[$mod_name] = $uniqueid[$mod_name] + 1; $mod_name = $mod_name . '[' . $uniqueid[$mod_name] . ']'; array_push($mod_name_array, $mod_name); // getting all the unique Names into the array if ($row['qtyinstock'] == '') { $mod_count_array[$mod_name] = 1; } else { $mod_count_array[$mod_name] = $row['qtyinstock']; } } } if (in_array($search_str, $search_str_array) == false) { array_push($search_str_array, $search_str); } //Counting the number of values for a type of graph if ($graph_for == "productname") { if ($row['qtyinstock'] == '') { $mod_count_array[$mod_name] = 1; } else { $mod_count_array[$mod_name] = $row['qtyinstock']; } } else { if (!isset($mod_count_array[$mod_name])) { $mod_count_array[$mod_name] = 0; } $mod_count_array[$mod_name]++; } //Counting the number of values for a type of graph for a particular date if (!isset($count_by_date[$mod_name][$crtd_date])) { $count_by_date[$mod_name][$crtd_date] = 0; } $count_by_date[$mod_name][$crtd_date] += 1; } $mod_by_mod_cnt = count($mod_name_array); if ($mod_by_mod_cnt != 0) { $url_string = ""; $mod_cnt_table = "<table border=0 cellspacing=1 cellpadding=3><tr>\r\n\t\t\t\t<th> Status </th>"; //Assigning the Header values to the vtiger_table and giving the dates as graphformat for ($i = 0; $i < $days; $i++) { $tdate = $date_array[$i]; $values = Graph_n_table_format($period_type, $tdate); $graph_format = $values[0]; $table_format = $values[1]; $mod_cnt_table .= "<th>{$table_format}</th>"; } $mod_cnt_table .= "<th>Total</th></tr>"; //For all type of the array for ($i = 0; $i < count($mod_name_array); $i++) { $search_str = $search_str_array[$i]; $mod_name = $mod_name_array[$i]; $id_name = ""; if ($mod_name == "Un Assigned") { $mod_name = $mod_strings["Un Assigned"]; $search_str = " "; } if ($graph_for == "accountid") { $name_val_table = get_account_name($mod_name); } else { $name_val_table = $mod_name; } $mod_cnt_table .= "<tr><td>{$name_val_table}</td>"; $mod_cnt_crtd_date = ""; //For all the days for ($j = 0; $j < $days; $j++) { $tdate = $date_array[$j]; if (!isset($count_by_date[$mod_name][$tdate])) { $count_by_date[$mod_name][$tdate] = "0"; } $cnt_by_date = $count_by_date[$mod_name][$tdate]; $mod_cnt_table .= "<td>{$cnt_by_date} </td>"; if ($i == 0) { $values = Graph_n_table_format($period_type, $tdate); $graph_format = $values[0]; $table_format = $values[1]; //passing the created dates to graph if ($mod_graph_date != "") { $mod_graph_date = "{$mod_graph_date},{$graph_format}"; } else { $mod_graph_date = "{$graph_format}"; } } //passing the name count by date to graph if ($mod_cnt_crtd_date != "") { $mod_cnt_crtd_date .= ",{$cnt_by_date}"; } else { $mod_cnt_crtd_date = "{$cnt_by_date}"; } } $mod_count_val = $mod_count_array[$mod_name]; $tot_mod_cnt = array_sum($count_by_date[$mod_name]); $mod_cnt_table .= "<td align=center>{$tot_mod_cnt}</td></tr>"; if ($graph_for == "accountid") { $name_val = get_account_name($mod_name); if ($name_val != "") { $mod_name = $name_val; $search_str = $name_val; } } if ($graph_for == "smownerid") { $name_val = getOwnerName($mod_name); if ($name_val != "") { $mod_name = $name_val; $search_str = $name_val; } } if ($graph_for == "product_id" || $graph_for == "productid") { $query = "SELECT productname FROM vtiger_products WHERE productid=?"; $result = $adb->pquery($query, array($mod_name)); $name_val = $adb->query_result($result, 0, "productname"); if ($name_val != "") { $mod_name = $name_val; $search_str = $name_val; } } if ($graph_for == "purchaseorderid") { $query = "SELECT subject FROM vtiger_purchaseorder WHERE purchaseorderid=?"; $result = $adb->pquery($query, array($mod_name)); $name_val = $adb->query_result($result, 0, "subject"); $id_name = $mod_name; if ($name_val != "") { $mod_name = $name_val; $search_str = $name_val; } } if ($graph_for == "quoteid") { $query = "SELECT subject FROM vtiger_quotes WHERE quoteid=?"; $result = $adb->pquery($query, array($mod_name)); $name_val = $adb->query_result($result, 0, "subject"); $id_name = $mod_name; if ($name_val != "") { $mod_name = $name_val; $search_str = $name_val; } } if ($graph_for == "invoiceid") { $query = "SELECT subject FROM vtiger_invoice WHERE invoiceid=?"; $result = $adb->pquery($query, array($mod_name)); $name_val = $adb->query_result($result, 0, "subject"); $id_name = $mod_name; if ($name_val != "") { $mod_name = $name_val; $search_str = $name_val; } } if ($graph_for == "campaignid") { //this will return the list of the names of the campaign``:w for the y-axis $query = "SELECT campaignname FROM vtiger_campaign WHERE campaignid=?"; $result = $adb->pquery($query, array($mod_name)); $name_val = $adb->query_result($result, 0, "campaignname"); $id_name = $mod_name; if ($name_val != "") { $mod_name = $name_val; $search_str = $name_val; } } if ($graph_for == "parent_id" || $graph_for == "related_to") { $seType = getSalesEntityType($mod_name); if ($seType == 'Contacts') { $query = "SELECT lastname, firstname FROM vtiger_contactdetails\r\n\t\t\t\t\t\t\tWHERE contactid=?"; $result = $adb->pquery($query, array($mod_name)); $name_val = $adb->query_result($result, 0, "lastname"); if ($name_val != "") { if (getFieldVisibilityPermission('Contacts', $current_user->id, 'firstname') == '0') { $first_name = $adb->query_result($result, 0, "firstname"); if ($first_name != '') { $name_val .= " " . $first_name; } } } } else { $query = "SELECT accountname FROM vtiger_account WHERE accountid=?"; $result = $adb->pquery($query, array($mod_name)); $name_val = $adb->query_result($result, 0, "accountname"); } $mod_name = $name_val; $search_str = $name_val; } //Passing name to graph $mod_name = str_replace(":", ":", $mod_name); if ($mod_name_val != "") { $mod_name_val .= "::{$mod_name}"; } else { $mod_name_val = "{$mod_name}"; } //Passing count to graph if ($mod_cnt_val != "") { $mod_cnt_val .= "::{$mod_count_val}"; } else { $mod_cnt_val = "{$mod_count_val}"; } if ($module != "") { //Check for Ticket Priority if ($graph_type == "ticketsbypriority") { $graph_for = "ticketpriorities"; } //added to get valid url in dashbord for tickets by team if ($graph_for == "smownerid") { $searchField = "assigned_user_id"; } elseif ($graph_for == 'category') { $searchField = 'ticketcategories'; } elseif ($graph_for == 'priority') { $searchField = 'ticketpriorities'; } elseif ($graph_for == "accountid") { $searchField = "account_id"; } else { $searchField = $graph_for; } $cvid = getCvIdOfAll($module); if ($module == "Home") { $cvid = getCvIdOfAll($mod_name); $link_val = "index.php?module=" . $mod_name . "&action=ListView&from_homepagedb=true&type=dbrd&query=true&owner=" . $current_user->user_name . "&viewname=" . $cvid; } else { if ($module == "Contacts" || $module == "Products" && ($graph_for == "quoteid" || $graph_for == "invoiceid" || $graph_for == "purchaseorderid")) { $link_val = "index.php?module=" . $module . "&action=ListView&from_dashboard=true&type=dbrd&query=true&" . $searchField . "=" . $id_name . "&viewname=" . $cvid; } else { $esc_search_str = urlencode($search_str); //$esc_search_str = htmlentities($search_str, ENT_QUOTES, $default_charset); $link_val = "index.php?module=" . $module . "&action=index&from_dashboard=true&search_text=" . $esc_search_str . "&search_field=" . $searchField . "&searchtype=BasicSearch&query=true&type=entchar&operator=e&viewname=" . $cvid; } } //Adding the links to the graph $link_val = str_replace(':', ':', $link_val); if ($i == 0) { $bar_target_val .= $link_val; } else { $bar_target_val .= "::" . $link_val; } } //The data as per given date if ($i == 0) { $urlstring .= $mod_cnt_crtd_date; } else { $urlstring .= "K" . $mod_cnt_crtd_date; } if ($i == 0) { $test_target_val .= $link_val; } else { $test_target_val .= "K" . $link_val; } } $mod_cnt_table .= "</tr><tr><td class=\"{$class}\">Total</td>"; //For all Days getting the vtiger_table for ($k = 0; $k < $days; $k++) { $tdate = $date_array[$k]; if (!isset($mod_tot_cnt_array[$tdate])) { $mod_tot_cnt_array[$tdate] = "0"; } $tot = $mod_tot_cnt_array[$tdate]; if ($period_type != "yday") { $mod_cnt_table .= "<td>{$tot}</td>"; } } if ($graph_for == "productname") { $cnt_total = array_sum($mod_count_array); } else { $cnt_total = array_sum($mod_tot_cnt_array); } $mod_cnt_table .= "<td align=\"center\" class=\"{$class}\">{$cnt_total}</td></tr></table>"; $mod_cnt_table .= "</table>"; $title_of_graph = "{$title} : {$cnt_total}"; $bar_target_val = urlencode($bar_target_val); $test_target_val = urlencode($test_target_val); $Prod_mod_val = array($mod_name_val, $mod_cnt_val, $title_of_graph, $bar_target_val, $mod_graph_date, $urlstring, $mod_cnt_table, $test_target_val); return $Prod_mod_val; } else { $data = 0; } } else { $data = 0; return "<h3> The data is not available with the specified time period</h3>"; } return $data; }
/** function used to get the top 5 recent FAQs from Listview query * @return array $values - array with the title, header and entries like Array('Title'=>$title,'Header'=>$listview_header,'Entries'=>$listview_entries) where as listview_header and listview_entries are arrays of header and entity values which are returned from function getListViewHeader and getListViewEntries */ function getMyFaq($maxval, $calCnt) { require_once "data/Tracker.php"; require_once 'modules/Faq/Faq.php'; require_once 'include/logging.php'; require_once 'include/ListView/ListView.php'; require_once 'include/utils/utils.php'; require_once 'modules/CustomView/CustomView.php'; global $current_language, $current_user, $list_max_entries_per_page, $adb; $current_module_strings = return_module_language($current_language, 'Faq'); $url_string = ''; $sorder = ''; $oCustomView = new CustomView("Faq"); if (isset($_REQUEST['viewname']) == false || $_REQUEST['viewname'] == '') { if ($oCustomView->setdefaultviewid != "") { $viewid = $oCustomView->setdefaultviewid; } else { $viewid = "0"; } } $focus = new Faq(); //Retreive the list from Database //<<<<<<<<<customview>>>>>>>>> $currentModule = 'Faq'; $viewId = getCvIdOfAll($currentModule); $queryGenerator = new QueryGenerator($currentModule, $current_user); $queryGenerator->initForCustomViewById($viewId); $meta = $queryGenerator->getMeta($currentModule); $accessibleFieldNameList = array_keys($meta->getModuleFields()); $customViewFields = $queryGenerator->getCustomViewFields(); $fields = $queryGenerator->getFields(); $newFields = array_diff($fields, $customViewFields); $widgetFieldsList = array('question', 'product_id'); $widgetFieldsList = array_intersect($accessibleFieldNameList, $widgetFieldsList); $widgetSelectedFields = array_chunk(array_intersect($customViewFields, $widgetFieldsList), 2); //select the first chunk of two fields $widgetSelectedFields = $widgetSelectedFields[0]; if (count($widgetSelectedFields) < 2) { $widgetSelectedFields = array_chunk(array_merge($widgetSelectedFields, $accessibleFieldNameList), 2); //select the first chunk of two fields $widgetSelectedFields = $widgetSelectedFields[0]; } $newFields = array_merge($newFields, $widgetSelectedFields); $queryGenerator->setFields($newFields); $_REQUEST = getMyFaqSearch($_REQUEST); $queryGenerator->addUserSearchConditions($_REQUEST); $search_qry = '&query=true' . getSearchURL($_REQUEST); $query = $queryGenerator->getQuery(); //<<<<<<<<customview>>>>>>>>> $query .= " LIMIT 0," . $adb->sql_escape_string($maxval); if ($calCnt == 'calculateCnt') { $list_result_rows = $adb->query(mkCountQuery($query)); return $adb->query_result($list_result_rows, 0, 'count'); } $list_result = $adb->query($query); //Retreiving the no of rows $noofrows = $adb->num_rows($list_result); //Retreiving the start value from request if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') { $start = vtlib_purify($_REQUEST['start']); } else { $start = 1; } //Retreive the Navigation array $navigation_array = getNavigationValues($start, $noofrows, $list_max_entries_per_page); if ($navigation_array['start'] == 1) { if ($noofrows != 0) { $start_rec = $navigation_array['start']; } else { $start_rec = 0; } if ($noofrows > $list_max_entries_per_page) { $end_rec = $navigation_array['start'] + $list_max_entries_per_page - 1; } else { $end_rec = $noofrows; } } else { if ($navigation_array['next'] > $list_max_entries_per_page) { $start_rec = $navigation_array['next'] - $list_max_entries_per_page; $end_rec = $navigation_array['next'] - 1; } else { $start_rec = $navigation_array['prev'] + $list_max_entries_per_page; $end_rec = $noofrows; } } //Retreive the List View Table Header $title = array('myFaqs.gif', $current_module_strings['LBL_MY_FAQ'], 'home_myfaq'); $controller = new ListViewController($adb, $current_user, $queryGenerator); $controller->setHeaderSorting(false); $header = $controller->getListViewHeader($focus, $currentModule, $url_string, $sorder, $order_by, true); $entries = $controller->getListViewEntries($focus, $currentModule, $list_result, $navigation_array, true); $values = array('ModuleName' => 'Faq', 'Title' => $title, 'Header' => $header, 'Entries' => $entries, 'search_qry' => $search_qry); if ($noofrows == 0 || $noofrows > 0) { return $values; } }
/** * Creates pie chart image of opportunities by lead_source. * param $datax- the sales stage data to display in the x-axis * param $datay- the sum of opportunity amounts for each opportunity in each sales stage * to display in the y-axis * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.. * All Rights Reserved.. * Contributor(s): ______________________________________.. */ function pipeline_by_lead_source($legends = array('foo', 'bar'), $user_id = array('1'), $cache_file_name = 'a_file', $refresh = true, $width = 900, $height = 500) { global $log, $current_user; $log->debug("Entering pipeline_by_lead_source(" . $legends . ") method ..."); global $app_strings, $lang_crm, $current_module_strings, $log, $charset, $tmp_dir; global $theme; include_once 'Image/Graph.php'; include_once 'Image/Canvas.php'; $font = calculate_font_name($lang_crm); if (!file_exists($cache_file_name) || !file_exists($cache_file_name . '.map') || $refresh == true) { $log =& LoggerManager::getLogger('opportunity charts'); $log->debug("starting pipeline chart"); $log->debug("legends is:"); $log->debug($legends); $log->debug("user_id is: "); $log->debug($user_id); $log->debug("cache_file_name is: {$cache_file_name}"); //Now do the db queries //query for opportunity data that matches $legends and $user $where = ""; //build the where clause for the query that matches $datax $count = count($legends); if ($count > 0) { $where .= " leadsource in ( "; $ls_i = 0; foreach ($legends as $key => $value) { if ($ls_i != 0) { $where .= ", "; } $where .= "'" . addslashes($key) . "'"; $ls_i++; } $where .= ")"; } $opp = new Potentials(); $opp_list = $opp->get_full_list("vtiger_potential.amount DESC, vtiger_potential.closingdate DESC", $where); //build pipeline by lead source data $total = 0; $count = array(); $sum = array(); if (isset($opp_list)) { foreach ($opp_list as $record) { if (!isset($sum[$record->column_fields['leadsource']])) { $sum[$record->column_fields['leadsource']] = 0; } if (isset($record->column_fields['amount']) && isset($record->column_fields['leadsource'])) { // Strip all non numbers from this string. $amount = CurrencyField::convertFromMasterCurrency(preg_replace('/[^0-9]/', '', floor($record->column_fields['amount'])), $current_user->conv_rate); $sum[$record->column_fields['leadsource']] = $sum[$record->column_fields['leadsource']] + $amount / 1000; if (isset($count[$record->column_fields['leadsource']])) { $count[$record->column_fields['leadsource']]++; } else { $count[$record->column_fields['leadsource']] = 1; } $total = $total + $amount / 1000; } } } $visible_legends = array(); $data = array(); $aTargets = array(); $aAlts = array(); foreach ($legends as $lead_source_key => $lead_source_translation) { if (isset($sum[$lead_source_key])) { array_push($data, $sum[$lead_source_key]); if ($lead_source_key != '') { array_push($visible_legends, $lead_source_translation); } else { // put none in if the vtiger_field is blank. array_push($visible_legends, $current_module_strings['NTC_NO_LEGENDS']); } $cvid = getCvIdOfAll("Potentials"); array_push($aTargets, "index.php?module=Potentials&action=ListView&leadsource=" . urlencode($lead_source_key) . "&query=true&type=dbrd&viewname=" . $cvid); array_push($aAlts, $count[$lead_source_key] . " " . $current_module_strings['LBL_OPPS_IN_LEAD_SOURCE'] . " {$lead_source_translation}\t"); } } $log->debug("sum is:"); $log->debug($sum); $log->debug("count is:"); $log->debug($count); $log->debug("total is: {$total}"); if ($total == 0) { $log->debug("Exiting pipeline_by_lead_source method ..."); return $current_module_strings['ERR_NO_OPPS']; } if ($theme == "blue") { $font_color = "#212473"; } else { $font_color = "#000000"; } $canvas =& Image_Canvas::factory('png', array('width' => $width, 'height' => $height, 'usemap' => true)); $imagemap = $canvas->getImageMap(); $graph =& Image_Graph::factory('graph', $canvas); $font =& $graph->addNew('font', calculate_font_name($lang_crm)); // set the font size to 11 pixels $font->setSize(8); $font->setColor($font_color); $graph->setFont($font); // create the plotarea layout $title =& Image_Graph::factory('title', array('Test', 10)); $plotarea =& Image_Graph::factory('plotarea', array('category', 'axis')); $footer =& Image_Graph::factory('title', array('Footer', 8)); $graph->add(Image_Graph::vertical($title, Image_Graph::vertical($plotarea, $footer, 90), 5)); // Generate colours $colors = color_generator(count($visible_legends), '#33CCFF', '#3322FF'); $index = 0; $dataset =& Image_Graph::factory('dataset'); $fills =& Image_Graph::factory('Image_Graph_Fill_Array'); foreach ($visible_legends as $legend) { $dataset->addPoint($legend, $data[$index], array('url' => $aTargets[$index], 'alt' => $aAlts[$index])); $fills->addColor($colors[$index]); $log->debug('point =' . $legend . ',' . $data[$index]); $index++; } // create the pie chart and associate the filling colours $gbplot =& $plotarea->addNew('pie', $dataset); $plotarea->hideAxis(); $gbplot->setFillStyle($fills); // Setup title $titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'] . $current_user->currency_symbol . $total . $app_strings['LBL_THOUSANDS_SYMBOL']; //$titlestr = $current_module_strings['LBL_TOTAL_PIPELINE'].$current_user->currency_symbol.$total; $title->setText($titlestr); // format the data values $valueproc =& Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', $current_user->currency_symbol . "%d"); // set markers $marker =& $graph->addNew('value_marker', IMAGE_GRAPH_VALUE_Y); $marker->setDataPreprocessor($valueproc); $marker->setFillColor('#FFFFFF'); $marker->setBorderColor($font_color); $marker->setFontColor($font_color); $marker->setFontSize(8); $pointingMarker =& $graph->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$marker)); $gbplot->setMarker($pointingMarker); // set legend $legend_box =& $plotarea->addNew('legend'); $legend_box->setPadding(array('top' => 20, 'bottom' => 0, 'left' => 0, 'right' => 0)); $legend_box->setFillColor('#F5F5F5'); $legend_box->showShadow(); $subtitle = $current_module_strings['LBL_OPP_SIZE'] . $current_user->currency_symbol . $current_module_strings['LBL_OPP_SIZE_VALUE']; $footer->setText($subtitle); $footer->setAlignment(IMAGE_GRAPH_ALIGN_TOP_LEFT); $imgMap = $graph->done(array('tohtml' => true, 'border' => 0, 'filename' => $cache_file_name, 'filepath' => './', 'urlpath' => '')); //$imgMap = htmlspecialchars($output); save_image_map($cache_file_name . '.map', $imgMap); } else { $imgMap_fp = fopen($cache_file_name . '.map', "rb"); $imgMap = fread($imgMap_fp, filesize($cache_file_name . '.map')); fclose($imgMap_fp); } $fileModTime = filemtime($cache_file_name . '.map'); $return = "\n{$imgMap}"; $log->debug("Exiting pipeline_by_lead_source method ..."); return $return; }
public static function generateChartDataFromReports($queryResult, $groupbyField, $fieldDetails = '', $reportid = '') { require_once 'modules/Reports/CustomReportUtils.php'; require_once 'include/Webservices/Utils.php'; require_once 'include/Webservices/Query.php'; global $adb, $current_user, $theme, $default_charset; $inventorymodules = array('Quotes', 'SalesOrder', 'PurchaseOrder', 'Invoice', 'Products', 'PriceBooks', 'Vendors', 'Services'); $rows = $adb->num_rows($queryResult); $condition = "is"; $current_theme = $theme; $groupByFields = array(); $yaxisArray = array(); $ChartDataArray = array(); $target_val = array(); $report = new ReportRun($reportid); $restrictedModules = array(); if ($report->secondarymodule != '') { $reportModules = explode(":", $report->secondarymodule); } else { $reportModules = array(); } array_push($reportModules, $report->primarymodule); $restrictedModules = false; foreach ($reportModules as $mod) { if (isPermitted($mod, 'index') != "yes" || vtlib_isModuleActive($mod) == false) { if (!is_array($restrictedModules)) { $restrictedModules = array(); } $restrictedModules[] = $mod; } } if (is_array($restrictedModules) && count($restrictedModules) > 0) { $ChartDataArray['error'] = "<h4>" . getTranslatedString('LBL_NO_ACCESS', 'Reports') . ' - ' . implode(',', $restrictedModules) . "</h4>"; return $ChartDataArray; } if ($fieldDetails != '') { list($tablename, $colname, $module_field, $fieldname, $single) = explode(":", $fieldDetails); list($module, $field) = split("_", $module_field); $dateField = false; if ($single == 'D') { $dateField = true; $query = "SELECT * FROM vtiger_reportgroupbycolumn WHERE reportid=? ORDER BY sortid"; $result = $adb->pquery($query, array($reportid)); $criteria = $adb->query_result($result, 0, 'dategroupbycriteria'); } } preg_match('/&/', $groupbyField, $matches); if (!empty($matches)) { $groupfield = str_replace('&', '&', $groupbyField); $groupbyField = $report->replaceSpecialChar($groupfield); } $handler = vtws_getModuleHandlerFromName($module, $current_user); $meta = $handler->getMeta(); $meta->retrieveMeta(); $referenceFields = $meta->getReferenceFieldDetails(); if ($rows > 0) { $resultRow = $adb->query_result_rowdata($queryResult, 0); if (!array_key_exists($groupbyField, $resultRow)) { $ChartDataArray['error'] = "<h4>" . getTranslatedString('LBL_NO_PERMISSION_FIELD', 'Dashboard') . "</h4>"; return $ChartDataArray; } } for ($i = 0; $i < $rows; $i++) { $groupFieldValue = $adb->query_result($queryResult, $i, strtolower($groupbyField)); $decodedGroupFieldValue = html_entity_decode($groupFieldValue, ENT_QUOTES, $default_charset); if (!empty($groupFieldValue)) { if (in_array($module_field, $report->append_currency_symbol_to_value)) { $valueComp = explode('::', $groupFieldValue); $groupFieldValue = $valueComp[1]; } if ($dateField) { if (!empty($groupFieldValue)) { $groupByFields[] = CustomReportUtils::getXAxisDateFieldValue($groupFieldValue, $criteria); } else { $groupByFields[] = "Null"; } } else { if (in_array($fieldname, array_keys($referenceFields))) { if (count($referenceFields[$fieldname]) > 1) { $refenceModule = CustomReportUtils::getEntityTypeFromName($decodedGroupFieldValue, $referenceFields[$fieldname]); } else { $refenceModule = $referenceFields[$fieldname][0]; } $groupByFields[] = $groupFieldValue; if ($fieldname == 'currency_id' && in_array($module, $inventorymodules)) { $tablename = 'vtiger_currency_info'; } elseif ($refenceModule == 'DocumentFolders' && $fieldname == 'folderid') { $tablename = 'vtiger_attachmentsfolder'; $colname = 'foldername'; } else { require_once "modules/{$refenceModule}/{$refenceModule}.php"; $focus = new $refenceModule(); $tablename = $focus->table_name; $colname = $focus->list_link_field; $condition = "c"; } } else { $groupByFields[] = $groupFieldValue; } } $yaxisArray[] = $adb->query_result($queryResult, $i, 'groupby_count'); if ($fieldDetails != '') { if ($dateField) { $advanceSearchCondition = CustomReportUtils::getAdvanceSearchCondition($fieldDetails, $criteria, $groupFieldValue); if ($module == 'Calendar') { $link_val = "index.php?module=" . $module . "&query=true&action=ListView&" . $advanceSearchCondition; } else { $link_val = "index.php?module=" . $module . "&query=true&action=index&" . $advanceSearchCondition; } } else { $cvid = getCvIdOfAll($module); $esc_search_str = urlencode($decodedGroupFieldValue); if ($single == 'DT') { $esc_search_str = urlencode($groupFieldValue); if (strtolower($fieldname) == 'modifiedtime' || strtolower($fieldname) == 'createdtime') { $tablename = 'vtiger_crmentity'; $colname = $fieldname; } } if ($fieldname == 'assigned_user_id') { $tablename = 'vtiger_crmentity'; $colname = 'smownerid'; } if ($fieldname == 'serviceid' && in_array($module, getInventoryModules())) { $fieldname = 'productid'; } if ($module == 'Calendar') { $link_val = "index.php?module=" . $module . "&action=ListView&search_text=" . $esc_search_str . "&search_field=" . $fieldname . "&searchtype=BasicSearch&query=true&operator=e&viewname=" . $cvid; } else { $link_val = "index.php?module=" . $module . "&action=index&search_text=" . $esc_search_str . "&search_field=" . $fieldname . "&searchtype=BasicSearch&query=true&operator=e&viewname=" . $cvid; } } $target_val[] = $link_val; } } } if (count($groupByFields) == 0) { $ChartDataArray['error'] = "<div class='componentName'>" . getTranslatedString('LBL_NO_DATA', 'Reports') . "</div"; } $ChartDataArray['xaxisData'] = $groupByFields; $ChartDataArray['yaxisData'] = $yaxisArray; $ChartDataArray['targetLink'] = $target_val; $theme = $current_theme; return $ChartDataArray; }