/** * this function returns the tasks allocated to different groups */ function getGroupTaskLists($maxval, $calCnt) { //get all the group relation tasks global $current_user; global $adb; global $log; global $app_strings; $userid = $current_user->id; $groupids = explode(",", fetchUserGroupids($userid)); //Check for permission before constructing the query. if (vtlib_isModuleActive("Leads") && count($groupids) > 0 && (isPermitted('Leads', 'index') == "yes" || isPermitted('Calendar', 'index') == "yes" || isPermitted('HelpDesk', 'index') == "yes" || isPermitted('Potentials', 'index') == "yes" || isPermitted('Accounts', 'index') == "yes" || isPermitted('Contacts', 'index') == 'yes' || isPermitted('Campaigns', 'index') == 'yes' || isPermitted('SalesOrder', 'index') == 'yes' || isPermitted('Invoice', 'index') == 'yes' || isPermitted('PurchaseOrder', 'index') == 'yes')) { $query = ''; $params = array(); if (isPermitted('Leads', 'index') == "yes") { $query = "select vtiger_leaddetails.leadid as id,vtiger_leaddetails.lastname as name,vtiger_groups.groupname as groupname, 'Leads ' as Type from vtiger_leaddetails inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_leaddetails.leadid inner join vtiger_groups on vtiger_crmentity.smownerid=vtiger_groups.groupid where vtiger_crmentity.deleted=0 and vtiger_leaddetails.leadid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("Calendar") && isPermitted('Calendar', 'index') == "yes") { if ($query != '') { $query .= " union all "; } //Get the activities assigned to group $query .= "select vtiger_activity.activityid as id,vtiger_activity.subject as name,vtiger_groups.groupname as groupname,'Activities' as Type from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_activity.activityid inner join vtiger_groups on vtiger_crmentity.smownerid=vtiger_groups.groupid where vtiger_crmentity.deleted=0 and ((vtiger_activity.eventstatus !='held'and (vtiger_activity.status is null or vtiger_activity.status ='')) or (vtiger_activity.status !='completed' and (vtiger_activity.eventstatus is null or vtiger_activity.eventstatus=''))) and vtiger_activity.activityid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("HelpDesk") && isPermitted('HelpDesk', 'index') == "yes") { if ($query != '') { $query .= " union all "; } //Get the tickets assigned to group (status not Closed -- hardcoded value) $query .= "select vtiger_troubletickets.ticketid,vtiger_troubletickets.title as name,vtiger_groups.groupname,'Tickets ' as Type from vtiger_troubletickets inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_troubletickets.ticketid inner join vtiger_groups on vtiger_crmentity.smownerid=vtiger_groups.groupid where vtiger_crmentity.deleted=0 and vtiger_troubletickets.status != 'Closed' and vtiger_troubletickets.ticketid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("Potentials") && isPermitted('Potentials', 'index') == "yes") { if ($query != '') { $query .= " union all "; } //Get the potentials assigned to group(sales stage not Closed Lost or Closed Won-- hardcoded value) $query .= "select vtiger_potential.potentialid,vtiger_potential.potentialname as name,vtiger_groups.groupname as groupname,'Potentials ' as Type from vtiger_potential inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_potential.potentialid inner join vtiger_groups on vtiger_crmentity.smownerid = vtiger_groups.groupid where vtiger_crmentity.deleted=0 and ((vtiger_potential.sales_stage !='Closed Lost') or (vtiger_potential.sales_stage != 'Closed Won')) and vtiger_potential.potentialid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("Accounts") && isPermitted('Accounts', 'index') == "yes") { if ($query != '') { $query .= " union all "; } //Get the Accounts assigned to group $query .= "select vtiger_account.accountid as id,vtiger_account.accountname as name,vtiger_groups.groupname as groupname, 'Accounts ' as Type from vtiger_account inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_account.accountid inner join vtiger_groups on vtiger_crmentity.smownerid=vtiger_groups.groupid where vtiger_crmentity.deleted=0 and vtiger_account.accountid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("Contacts") && isPermitted('Contacts', 'index') == 'yes') { if ($query != '') { $query .= " union all "; } //Get the Contacts assigned to group $query .= "select vtiger_contactdetails.contactid as id, vtiger_contactdetails.lastname as name ,vtiger_groups.groupname as groupname, 'Contacts ' as Type from vtiger_contactdetails inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_contactdetails.contactid inner join vtiger_groups on vtiger_crmentity.smownerid = vtiger_groups.groupid where vtiger_crmentity.deleted=0 and vtiger_contactdetails.contactid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("Campaigns") && isPermitted('Campaigns', 'index') == 'yes') { if ($query != '') { $query .= " union all "; } //Get the Campaigns assigned to group(Campaign status not Complete -- hardcoded value) $query .= "select vtiger_campaign.campaignid as id, vtiger_campaign.campaignname as name, vtiger_groups.groupname as groupname,'Campaigns ' as Type from vtiger_campaign inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_campaign.campaignid inner join vtiger_groups on vtiger_crmentity.smownerid = vtiger_groups.groupid where vtiger_crmentity.deleted=0 and (vtiger_campaign.campaignstatus != 'Complete') and vtiger_campaign.campaignid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("Quotes") && isPermitted('Quotes', 'index') == 'yes') { if ($query != '') { $query .= " union all "; } //Get the Quotes assigned to group(Quotes stage not Rejected -- hardcoded value) $query .= "select vtiger_quotes.quoteid as id,vtiger_quotes.subject as name, vtiger_groups.groupname as groupname ,'Quotes 'as Type from vtiger_quotes inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_quotes.quoteid inner join vtiger_groups on vtiger_crmentity.smownerid = vtiger_groups.groupid where vtiger_crmentity.deleted=0 and (vtiger_quotes.quotestage != 'Rejected') and vtiger_quotes.quoteid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("SalesOrder") && isPermitted('SalesOrder', 'index') == 'yes') { if ($query != '') { $query .= " union all "; } //Get the Sales Order assigned to group $query .= "select vtiger_salesorder.salesorderid as id, vtiger_salesorder.subject as name,vtiger_groups.groupname as groupname,'SalesOrder ' as Type from vtiger_salesorder inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_salesorder.salesorderid inner join vtiger_groups on vtiger_crmentity.smownerid = vtiger_groups.groupid where vtiger_crmentity.deleted=0 and vtiger_salesorder.salesorderid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("Invoice") && isPermitted('Invoice', 'index') == 'yes') { if ($query != '') { $query .= " union all "; } //Get the Sales Order assigned to group(Invoice status not Paid -- hardcoded value) $query .= "select vtiger_invoice.invoiceid as Id , vtiger_invoice.subject as Name, vtiger_groups.groupname as groupname,'Invoice ' as Type from vtiger_invoice inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_invoice.invoiceid inner join vtiger_groups on vtiger_crmentity.smownerid = vtiger_groups.groupid where vtiger_crmentity.deleted=0 and(vtiger_invoice.invoicestatus != 'Paid') and vtiger_invoice.invoiceid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("PurchaseOrder") && isPermitted('PurchaseOrder', 'index') == 'yes') { if ($query != '') { $query .= " union all "; } //Get the Purchase Order assigned to group $query .= "select vtiger_purchaseorder.purchaseorderid as id,vtiger_purchaseorder.subject as name,vtiger_groups.groupname as groupname, 'PurchaseOrder ' as Type from vtiger_purchaseorder inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_purchaseorder.purchaseorderid inner join vtiger_groups on vtiger_crmentity.smownerid =vtiger_groups.groupid where vtiger_crmentity.deleted=0 and vtiger_purchaseorder.purchaseorderid >0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } if (vtlib_isModuleActive("Documents") && isPermitted('Documents', 'index') == 'yes') { if ($query != '') { $query .= " union all "; } //Get the Purchase Order assigned to group $query .= "select vtiger_notes.notesid as id,vtiger_notes.title as name,vtiger_groups.groupname as groupname, 'Documents' as Type from vtiger_notes inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_notes.notesid inner join vtiger_groups on vtiger_crmentity.smownerid =vtiger_groups.groupid where vtiger_crmentity.deleted=0 and vtiger_notes.notesid > 0"; if (count($groupids) > 0) { $query .= " and vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . ")"; array_push($params, $groupids); } $query .= " LIMIT {$maxval}"; } $log->info("Here is the where clause for the list view: {$query}"); $result = $adb->pquery($query, $params) or die("Couldn't get the group listing"); $title = array(); $title[] = 'myGroupAllocation.gif'; $title[] = $app_strings['LBL_GROUP_ALLOCATION_TITLE']; $title[] = 'home_mygrp'; $header = array(); $header[] = $app_strings['LBL_ENTITY_NAME']; $header[] = $app_strings['LBL_GROUP_NAME']; $header[] = $app_strings['LBL_ENTITY_TYPE']; if (count($groupids) > 0) { $i = 1; while ($row = $adb->fetch_array($result)) { $value = array(); $row["type"] = trim($row["type"]); if ($row["type"] == "Tickets") { $list = '<a href=index.php?module=HelpDesk'; $list .= '&action=DetailView&record=' . $row["id"] . '>' . $row["name"] . '</a>'; } elseif ($row["type"] == "Activities") { $row["type"] = 'Calendar'; $acti_type = getActivityType($row["id"]); $list = '<a href=index.php?module=' . $row["type"]; if ($acti_type == 'Task') { $list .= '&activity_mode=Task'; } elseif ($acti_type == 'Call' || $acti_type == 'Meeting') { $list .= '&activity_mode=Events'; } $list .= '&action=DetailView&record=' . $row["id"] . '>' . $row["name"] . '</a>'; } else { $list = '<a href=index.php?module=' . $row["type"]; $list .= '&action=DetailView&record=' . $row["id"] . '>' . $row["name"] . '</a>'; } $value[] = $list; $value[] = $row["groupname"]; $value[] = $row["type"]; $entries[$row["id"]] = $value; $i++; } } $values = array('Title' => $title, 'Header' => $header, 'Entries' => $entries); if (count($entries) > 0) { return $values; } } }
/** * Function to get todos list scheduled between specified dates * @param array $calendar - collection of objects and strings * @param string $start_date - date string * @param string $end_date - date string * @param string $info - string 'listcnt' or empty string. if 'listcnt' means it returns no. of todos and no. of pending todos in array format else it returns todos list in array format * return array $Entries - todolists in array format */ function getTodoList(&$calendar, $start_date, $end_date, $info = '') { global $log, $app_strings, $theme; $Entries = array(); $category = getParentTab(); global $adb, $current_user, $mod_strings, $cal_log, $list_max_entries_per_page; $cal_log->debug("Entering getTodoList() method..."); require 'user_privileges/user_privileges_' . $current_user->id . '.php'; require 'user_privileges/sharing_privileges_' . $current_user->id . '.php'; $count_qry = "SELECT count(*) as count FROM vtiger_activity\n\t\tINNER JOIN vtiger_crmentity\n\t\tON vtiger_crmentity.crmid = vtiger_activity.activityid\n\t\tLEFT JOIN vtiger_cntactivityrel\n\t\tON vtiger_cntactivityrel.activityid = vtiger_activity.activityid\n\t\tLEFT JOIN vtiger_groups\n\t\tON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\tLEFT JOIN vtiger_users\n\t\tON vtiger_users.id = vtiger_crmentity.smownerid\n\t\tWHERE vtiger_crmentity.deleted = 0\n\t\tAND vtiger_activity.activitytype = 'Task'\n\t\tAND (vtiger_activity.date_start BETWEEN ? AND ?) AND vtiger_crmentity.smownerid = " . $current_user->id; $query = "SELECT vtiger_groups.groupname, vtiger_users.user_name, vtiger_crmentity.crmid, vtiger_cntactivityrel.contactid, \n\t\t\t\tvtiger_activity.* FROM vtiger_activity\n INNER JOIN vtiger_crmentity\n\t\t\t\t\tON vtiger_crmentity.crmid = vtiger_activity.activityid\n LEFT JOIN vtiger_cntactivityrel\n\t\t\t\t\tON vtiger_cntactivityrel.activityid = vtiger_activity.activityid\n\t\t\t\tLEFT JOIN vtiger_groups\n\t\t\t\t\tON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\t\t\tLEFT JOIN vtiger_users\n\t\t\t\t\tON vtiger_users.id = vtiger_crmentity.smownerid\n WHERE vtiger_crmentity.deleted = 0\n\t\t\t\t\tAND vtiger_activity.activitytype = 'Task'\n\t\t\t\t\tAND (vtiger_activity.date_start BETWEEN ? AND ?) AND vtiger_crmentity.smownerid = " . $current_user->id; $list_query = $query; // User Select Customization /*$only_for_user = calendarview_getSelectedUserId(); if($only_for_user != 'ALL') { $query .= " AND vtiger_crmentity.smownerid = " . $only_for_user; $count_qry .= " AND vtiger_crmentity.smownerid = " . $only_for_user; }*/ // END $params = $info_params = array($start_date, $end_date); if ($info != '') { //added to fix #4816 $groupids = explode(",", fetchUserGroupids($current_user->id)); if (count($groupids) > 0) { $com_q = " AND (vtiger_crmentity.smownerid = ?\n\t\t\t\t\tOR vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . "))"; } else { $com_q = " AND vtiger_crmentity.smownerid = ?"; } //end $pending_query = $query . " AND (vtiger_activity.status != 'Completed')" . $com_q; $total_q = $query . "" . $com_q; array_push($info_params, $current_user->id); if (count($groupids) > 0) { array_push($info_params, $groupids); } if ($adb->dbType == "pgsql") { $pending_query = fixPostgresQuery($pending_query, $log, 0); $total_q = fixPostgresQuery($total_q, $log, 0); } $total_res = $adb->pquery($total_q, $info_params); $total = $adb->num_rows($total_res); $res = $adb->pquery($pending_query, $info_params); $pending_rows = $adb->num_rows($res); $cal_log->debug("Exiting getTodoList() method..."); return array('totaltodo' => $total, 'pendingtodo' => $pending_rows); } if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[9] == 3) { $sec_parameter = getListViewSecurityParameter('Calendar'); $query .= $sec_parameter; $list_query .= $sec_parameter; $count_qry .= $sec_parameter; } $group_cond = ''; $count_res = $adb->pquery($count_qry, $params); $total_rec_count = $adb->query_result($count_res, 0, 'count'); $group_cond .= " ORDER BY vtiger_activity.date_start,vtiger_activity.time_start ASC"; if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') { $start = vtlib_purify($_REQUEST['start']); } else { $start = 1; } $navigation_array = getNavigationValues($start, $total_rec_count, $list_max_entries_per_page); $start_rec = $navigation_array['start']; $end_rec = $navigation_array['end_val']; if ($start_rec <= 1) { $start_rec = 0; } else { $start_rec = $start_rec - 1; } $query .= $group_cond . " limit {$start_rec},{$list_max_entries_per_page}"; $list_query .= $group_cond; if ($adb->dbType == "pgsql") { $query = fixPostgresQuery($query, $log, 0); $list_query = fixPostgresQuery($list_query, $log, 0); } $list_query = $adb->convert2Sql($list_query, $params); $_SESSION['Calendar_listquery'] = $list_query; $result = $adb->pquery($query, $params); $rows = $adb->num_rows($result); $c = 0; if ($start > 1) { $c = ($start - 1) * $list_max_entries_per_page; } for ($i = 0; $i < $rows; $i++) { $element = array(); $contact_name = ''; $element['no'] = $c + 1; $more_link = ""; $start_time = $adb->query_result($result, $i, "time_start"); $format = $calendar['calendar']->hour_format; $value = getaddEventPopupTime($start_time, $start_time, $format); $element['starttime'] = $value['starthour'] . ':' . $value['startmin'] . '' . $value['startfmt']; $date_start = $adb->query_result($result, $i, "date_start"); $due_date = $adb->query_result($result, $i, "due_date"); if ($calendar['view'] != 'day') { $element['startdate'] = getDisplayDate($date_start); } $element['duedate'] = getDisplayDate($due_date); $id = $adb->query_result($result, $i, "activityid"); $subject = $adb->query_result($result, $i, "subject"); //CHANGE : TO IMPROVE PERFORMANCE /*$contact_id = $adb->query_result($result,$i,"contactid"); if($contact_id!='') { $contact_name = getContactName($contact_id); }*/ $more_link = "<a href='index.php?action=DetailView&module=Calendar&record=" . $id . "&activity_mode=Task&viewtype=calendar&parenttab=" . $category . "' class='webMnu'>" . $subject . "</a>"; $element['tododetail'] = $more_link; /*if(getFieldVisibilityPermission('Calendar',$current_user->id,'parent_id') == '0') { $element['task_relatedto'] = getRelatedTo('Calendar',$result,$i); } if(getFieldVisibilityPermission('Calendar',$current_user->id,'contact_id') == '0') { $element['task_contact'] = "<a href=\"index.php?module=Contacts&action=DetailView&record=".$contact_id."\">".$contact_name."</a>"; }*/ if (getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0') { $taskstatus = $adb->query_result($result, $i, "status"); if (!$is_admin && $taskstatus != '') { $roleid = $current_user->roleid; $roleids = array(); $subrole = getRoleSubordinates($roleid); if (count($subrole) > 0) { $roleids = $subrole; } array_push($roleids, $roleid); //here we are checking wheather the table contains the sortorder column .If sortorder is present in the main picklist table, then the role2picklist will be applicable for this table... $sql = "select * from vtiger_taskstatus where taskstatus=?"; $res = $adb->pquery($sql, array(decode_html($taskstatus))); $picklistvalueid = $adb->query_result($res, 0, 'picklist_valueid'); if ($picklistvalueid != null) { $pick_query = "select * from vtiger_role2picklist where picklistvalueid={$picklistvalueid} and roleid in (" . generateQuestionMarks($roleids) . ")"; $res_val = $adb->pquery($pick_query, array($roleids)); $num_val = $adb->num_rows($res_val); } if ($num_val > 0) { $element['status'] = getTranslatedString(decode_html($taskstatus)); } else { $element['status'] = "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>"; } } else { $element['status'] = getTranslatedString(decode_html($taskstatus)); } } if (isPermitted("Calendar", "EditView") == "yes" || isPermitted("Calendar", "Delete") == "yes") { $element['action'] = "<img onClick='getcalAction(this,\"taskcalAction\"," . $id . ",\"" . $calendar['view'] . "\",\"" . $calendar['calendar']->date_time->hour . "\",\"" . $calendar['calendar']->date_time->get_formatted_date() . "\",\"todo\");' src='" . vtiger_imageurl('cal_event.jpg', $theme) . "' border='0'>"; } $assignedto = $adb->query_result($result, $i, "user_name"); if (!empty($assignedto)) { $element['assignedto'] = $assignedto; } else { $element['assignedto'] = $adb->query_result($result, $i, "groupname"); } $c++; $Entries[] = $element; } $ret_arr[0] = $Entries; $ret_arr[1] = $navigation_array; $cal_log->debug("Exiting getTodoList() method..."); return $ret_arr; }
function calendarview_getSelectedUserFilterQuerySuffix() { global $current_user, $adb; $only_for_user = calendarview_getSelectedUserId(); $qcondition = ''; if (!empty($only_for_user)) { if ($only_for_user != 'ALL') { // For logged in user include the group records also. if ($only_for_user == $current_user->id) { $user_group_ids = fetchUserGroupids($current_user->id); // User does not belong to any group? Let us reset to non-existent group if (!empty($user_group_ids)) { $user_group_ids .= ','; } else { $user_group_ids = ''; } $user_group_ids .= $current_user->id; $qcondition = " AND vtiger_crmentity.smownerid IN (" . $user_group_ids . ")"; } else { $qcondition = " AND vtiger_crmentity.smownerid = " . $adb->sql_escape_string($only_for_user); } } } return $qcondition; }
/** * Function to get todos list scheduled between specified dates * @param array $calendar - collection of objects and strings * @param string $start_date - date string * @param string $end_date - date string * @param string $info - string 'listcnt' or empty string. if 'listcnt' means it returns no. of todos and no. of pending todos in array format else it returns todos list in array format * return array $Entries - todolists in array format */ function getTodoList(&$calendar, $start_date, $end_date, $info = '') { global $log, $app_strings, $theme; $Entries = array(); $category = getParentTab(); global $adb, $current_user, $mod_strings, $cal_log, $list_max_entries_per_page; $cal_log->debug("Entering getTodoList() method..."); require 'user_privileges/user_privileges_' . $current_user->id . '.php'; require 'user_privileges/sharing_privileges_' . $current_user->id . '.php'; $userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users'); $query = "SELECT vtiger_groups.groupname, {$userNameSql} as user_name, vtiger_crmentity.crmid, vtiger_cntactivityrel.contactid,\n\t\t\t\tvtiger_activity.* FROM vtiger_activity\n INNER JOIN vtiger_crmentity\n\t\t\t\t\tON vtiger_crmentity.crmid = vtiger_activity.activityid\n LEFT JOIN vtiger_cntactivityrel\n\t\t\t\t\tON vtiger_cntactivityrel.activityid = vtiger_activity.activityid\n\t\t\t\tLEFT JOIN vtiger_groups\n\t\t\t\t\tON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\t\t\tLEFT JOIN vtiger_users\n\t\t\t\t\tON vtiger_users.id = vtiger_crmentity.smownerid"; $query .= getNonAdminAccessControlQuery('Calendar', $current_user); $query .= "WHERE vtiger_crmentity.deleted = 0 AND vtiger_activity.activitytype = 'Task'" . " AND ((CAST(CONCAT(date_start,' ',time_start) AS DATETIME) >= ? AND CAST(CONCAT(date_start,' ',time_start) AS DATETIME) <= ?)\n\t\t\t\t\t\t\tOR\t(CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ? AND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) <= ? )\n\t\t\t\t\t\t\tOR\t(CAST(CONCAT(date_start,' ',time_start) AS DATETIME) <= ? AND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ?)\n\t\t\t\t\t\t)"; $list_query = $query . " AND vtiger_crmentity.smownerid = " . $current_user->id; $startDate = new DateTimeField($start_date . ' 00:00'); $endDate = new DateTimeField($end_date . ' 23:59'); $params = $info_params = array($startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(), $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(), $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue()); if ($info != '') { //added to fix #4816 $groupids = explode(",", fetchUserGroupids($current_user->id)); if (count($groupids) > 0 && !is_admin($current_user)) { $com_q = " AND (vtiger_crmentity.smownerid = ?\n\t\t\t\t\tOR vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . "))"; array_push($info_params, $current_user->id); array_push($info_params, $groupids); } elseif (!is_admin($current_user)) { $com_q = " AND vtiger_crmentity.smownerid = ?"; array_push($info_params, $current_user->id); } //end $pending_query = $query . " AND (vtiger_activity.status != 'Completed')" . $com_q; $total_q = $query . "" . $com_q; $total_res = $adb->pquery($total_q, $info_params); $total = $adb->num_rows($total_res); $res = $adb->pquery($pending_query, $info_params); $pending_rows = $adb->num_rows($res); $cal_log->debug("Exiting getTodoList() method..."); return array('totaltodo' => $total, 'pendingtodo' => $pending_rows); } $group_cond = ''; $group_cond .= " ORDER BY vtiger_activity.date_start,vtiger_activity.time_start ASC"; if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') { $start = vtlib_purify($_REQUEST['start']); } else { $start = 1; } //T6477 changes if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) { $count_res = $adb->pquery(mkCountQuery($query), $params); $total_rec_count = $adb->query_result($count_res, 0, 'count'); } else { $total_rec_count = null; } $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $total_rec_count); $start_rec = ($start - 1) * $list_max_entries_per_page; $end_rec = $navigation_array['end_val']; $list_query = $adb->convert2Sql($query, $params); $_SESSION['Calendar_listquery'] = $list_query; if ($start_rec < 0) { $start_rec = 0; } //ends $query .= $group_cond . " limit {$start_rec},{$list_max_entries_per_page}"; $result = $adb->pquery($query, $params); $rows = $adb->num_rows($result); $c = 0; if ($start > 1) { $c = ($start - 1) * $list_max_entries_per_page; } for ($i = 0; $i < $rows; $i++) { $element = array(); $contact_name = ''; $element['no'] = $c + 1; $more_link = ""; $start_time = $adb->query_result($result, $i, "time_start"); $date_start = $adb->query_result($result, $i, "date_start"); $due_date = $adb->query_result($result, $i, "due_date"); $date = new DateTimeField($date_start . ' ' . $start_time); $endDate = new DateTimeField($due_date); if (!empty($start_time)) { $start_time = $date->getDisplayTime(); } $format = $calendar['calendar']->hour_format; $value = getaddEventPopupTime($start_time, $start_time, $format); $element['starttime'] = $value['starthour'] . ':' . $value['startmin'] . '' . $value['startfmt']; $element['startdate'] = $date->getDisplayDate(); $element['duedate'] = $endDate->getDisplayDate(); $id = $adb->query_result($result, $i, "activityid"); $subject = $adb->query_result($result, $i, "subject"); $more_link = "<a href='index.php?action=DetailView&module=Calendar&record=" . $id . "&activity_mode=Task&viewtype=calendar&parenttab=" . $category . "' class='webMnu'>" . $subject . "</a>"; $element['tododetail'] = $more_link; if (getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0') { $taskstatus = $adb->query_result($result, $i, "status"); if (!$is_admin && $taskstatus != '') { $roleid = $current_user->roleid; $roleids = array(); $subrole = getRoleSubordinates($roleid); if (count($subrole) > 0) { $roleids = $subrole; } array_push($roleids, $roleid); //here we are checking wheather the table contains the sortorder column .If sortorder is present in the main picklist table, then the role2picklist will be applicable for this table... $sql = "select * from vtiger_taskstatus where taskstatus=?"; $res = $adb->pquery($sql, array(decode_html($taskstatus))); $picklistvalueid = $adb->query_result($res, 0, 'picklist_valueid'); if ($picklistvalueid != null) { $pick_query = "select * from vtiger_role2picklist where picklistvalueid={$picklistvalueid} and roleid in (" . generateQuestionMarks($roleids) . ")"; $res_val = $adb->pquery($pick_query, array($roleids)); $num_val = $adb->num_rows($res_val); } if ($num_val > 0) { $element['status'] = getTranslatedString(decode_html($taskstatus)); } else { $element['status'] = "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>"; } } else { $element['status'] = getTranslatedString(decode_html($taskstatus)); } } if (isPermitted("Calendar", "EditView") == "yes" || isPermitted("Calendar", "Delete") == "yes") { $element['action'] = "<img onClick='getcalAction(this,\"taskcalAction\"," . $id . ",\"" . $calendar['view'] . "\",\"" . $calendar['calendar']->date_time->hour . "\",\"" . $calendar['calendar']->date_time->get_DB_formatted_date() . "\",\"todo\");' src='" . vtiger_imageurl('cal_event.jpg', $theme) . "' border='0'>"; } $assignedto = $adb->query_result($result, $i, "user_name"); if (!empty($assignedto)) { $element['assignedto'] = $assignedto; } else { $element['assignedto'] = $adb->query_result($result, $i, "groupname"); } $c++; $Entries[] = $element; } $ret_arr[0] = $Entries; $ret_arr[1] = $navigation_array; $cal_log->debug("Exiting getTodoList() method..."); return $ret_arr; }
public function CheckSharing($reports4youid) { // if this template belongs to current user $adb = PearDatabase::getInstance(); $sql = "SELECT owner, sharingtype FROM its4you_reports4you_settings WHERE reportid = ?"; $result = $adb->pquery($sql, array($reports4youid)); $row = $adb->fetchByAssoc($result); $owner = $row["owner"]; $sharingtype = $row["sharingtype"]; $result = false; if ($owner == $this->current_user->id || $this->current_user->is_admin == "on") { $result = true; } else { switch ($sharingtype) { //available for all case "public": $result = true; break; //available only for superordinate users of template owner, so we get list of all subordinate users of the current user and if template //owner is one of them then template is available for current user //available only for superordinate users of template owner, so we get list of all subordinate users of the current user and if template //owner is one of them then template is available for current user case "private": $subordinateUsers = $this->getSubRoleUserIds($this->current_user->roleid); if (!empty($subordinateUsers) && count($subordinateUsers) > 0) { $result = in_array($owner, $subordinateUsers); } else { $result = false; } break; //available only for those that are in share list //available only for those that are in share list case "share": $subordinateUsers = $this->getSubRoleUserIds($this->current_user->roleid); if (!empty($subordinateUsers) && count($subordinateUsers) > 0 && in_array($owner, $subordinateUsers)) { $result = true; } else { $member_array = $this->GetSharingMemberArray($reports4youid); if (isset($member_array["users"]) && in_array($this->current_user->id, $member_array["users"])) { $result = true; } elseif (isset($member_array["roles"]) && in_array($this->current_user->roleid, $member_array["roles"])) { $result = true; } else { if (isset($member_array["rs"])) { foreach ($member_array["rs"] as $roleid) { $roleAndsubordinateRoles = getRoleAndSubordinatesRoleIds($roleid); if (in_array($this->current_user->roleid, $roleAndsubordinateRoles)) { $result = true; break; } } } if ($result == false && isset($member_array["groups"])) { $current_user_groups = explode(",", fetchUserGroupids($this->current_user->id)); $res_array = array_intersect($member_array["groups"], $current_user_groups); if (!empty($res_array) && count($res_array) > 0) { $result = true; } else { $result = false; } } } } break; } } return $result; }
$s_sql = "SELECT taskstatus FROM vtiger_taskstatus WHERE picklist_valueid = ?"; $s_result = $adb->pquery($s_sql, array($sid)); $taskstatus = $adb->query_result($s_result, 0, "taskstatus"); array_push($Task_Status, $taskstatus); $taskstatus = html_entity_decode($taskstatus, ENT_QUOTES, $default_charset); array_push($Task_Status, $taskstatus); } } $showGroupEvents = GlobalVariable::getVariable('Calendar_Show_Group_Events', 1); $modtab = array_flip($tasklabel); foreach ($Users_Ids as $userid) { if (!$userid) { continue; } if ($showGroupEvents) { $groups = fetchUserGroupids($userid); } foreach ($Type_Ids as $activitytypeid) { $allDay = true; $list_array = array(); $invites = false; if (is_numeric($activitytypeid)) { $sql1 = "SELECT activitytype FROM vtiger_activitytype WHERE activitytypeid = ?"; $result1 = $adb->pquery($sql1, array($activitytypeid)); $activitytype = $adb->query_result($result1, 0, "activitytype"); $activitytype = html_entity_decode($activitytype, ENT_QUOTES, $default_charset); $allDay = false; } elseif ($activitytypeid == "invite") { $activitytype = $activitytypeid; $invites = true; $allDay = false;