public static function render($userInputObject, $user) { global $list_max_entries_per_page; $adb = PearDatabase::getInstance(); $viewer = new Import_UI_Viewer(); $ownerId = $userInputObject->get('foruser'); $owner = new Users(); $owner->id = $ownerId; $owner->retrieve_entity_info($ownerId, 'Users'); if (!is_admin($user) && $user->id != $owner->id) { $viewer->display('OperationNotPermitted.tpl', 'Vtiger'); exit; } $userDBTableName = Import_Utils::getDbTableName($owner); $moduleName = $userInputObject->get('module'); $moduleMeta = self::getModuleMeta($moduleName, $user); $result = $adb->query('SELECT recordid FROM ' . $userDBTableName . ' WHERE status is NOT NULL AND recordid IS NOT NULL'); $noOfRecords = $adb->num_rows($result); $importedRecordIds = array(); for ($i = 0; $i < $noOfRecords; ++$i) { $importedRecordIds[] = $adb->query_result($result, $i, 'recordid'); } if (count($importedRecordIds) == 0) { $importedRecordIds[] = 0; } $focus = CRMEntity::getInstance($moduleName); $queryGenerator = new QueryGenerator($moduleName, $user); $customView = new CustomView($moduleName); $viewId = $customView->getViewIdByName('All', $moduleName); $queryGenerator->initForCustomViewById($viewId); $list_query = $queryGenerator->getQuery(); // Fetch only last imported records $list_query .= ' AND ' . $focus->table_name . '.' . $focus->table_index . ' IN (' . implode(',', $importedRecordIds) . ')'; if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) { $count_result = $adb->query(mkCountQuery($list_query)); $noofrows = $adb->query_result($count_result, 0, "count"); } else { $noofrows = null; } $start = ListViewSession::getRequestCurrentPage($moduleName, $list_query, $viewId, false); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; $list_result = $adb->pquery($list_query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows); $viewer->assign('recordListRange', $recordListRangeMsg); $controller = new ListViewController($adb, $user, $queryGenerator); $listview_header = $controller->getListViewHeader($focus, $moduleName, $url_string, $sorder, $order_by, true); $listview_entries = $controller->getListViewEntries($focus, $moduleName, $list_result, $navigation_array, true); $viewer->assign('CURRENT_PAGE', $start); $viewer->assign('LISTHEADER', $listview_header); $viewer->assign('LISTENTITY', $listview_entries); $viewer->assign('FOR_MODULE', $moduleName); $viewer->assign('FOR_USER', $ownerId); $isAjax = $userInputObject->get('ajax'); if (!empty($isAjax)) { echo $viewer->fetch('ListViewEntries.tpl'); } else { $viewer->display('ImportListView.tpl'); } }
} $list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder; } } ///Postgres 8 fixes if ($adb->dbType == "pgsql") { $list_query = fixPostgresQuery($list_query, $log, 0); } if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) { $count_result = $adb->query(mkCountQuery($list_query)); $noofrows = $adb->query_result($count_result, 0, "count"); } else { $noofrows = null; } $queryMode = isset($_REQUEST['query']) && $_REQUEST['query'] == 'true'; $start = ListViewSession::getRequestCurrentPage($currentModule, $list_query, $viewid, $queryMode); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; if ($adb->dbType == "pgsql") { $list_result = $adb->pquery($list_query . " OFFSET {$limit_start_rec} LIMIT {$list_max_entries_per_page}", array()); } else { $list_result = $adb->pquery($list_query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); } $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec); $smarty->assign('recordListRange', $recordListRangeMsg); //Retreive the List View Table Header if ($viewid != '') { $url_string .= "&viewname=" . $viewid; } $listview_header = getListViewHeader($focus, "SalesOrder", $url_string, $sorder, $order_by, "", $oCustomView); $smarty->assign("LISTHEADER", $listview_header);
$smarty->assign("APP", $app_strings); $smarty->assign("THEME", $theme); $smarty->assign("IMAGE_PATH", $image_path); $smarty->assign("MODULE", $currentModule); $smarty->assign("SINGLE_MOD", getTranslatedString('SINGLE_' . $currentModule, $currentModule)); $smarty->assign("BUTTONS", $other_text); $smarty->assign("NEW_EVENT", $app_strings['LNK_NEW_EVENT']); $smarty->assign("NEW_TASK", $app_strings['LNK_NEW_TASK']); if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) { $count_result = $adb->query(mkCountQuery($list_query)); $noofrows = $adb->query_result($count_result, 0, "count"); } else { $noofrows = null; } $queryMode = isset($_REQUEST['query']) && $_REQUEST['query'] == 'true'; $start = ListViewSession::getRequestCurrentPage('Calendar', $list_query, $viewid, $queryMode); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; $list_result = $adb->pquery($list_query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); $recordListRangeMsg = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows); $smarty->assign('recordListRange', $recordListRangeMsg); //Retreive the List View Table Header if ($viewid != '') { $url_string .= "&viewname=" . $viewid; } if (!empty($viewid)) { if (!isset($oCustomView->list_fields['Close'])) { $oCustomView->list_fields['Close'] = array('vtiger_activity' => 'eventstatus'); } if (!isset($oCustomView->list_fields_name['Close'])) { $oCustomView->list_fields_name['Close'] = 'eventstatus';
/** * Function to get events 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 events and no. of pending events in array format else it returns events list in array format * return array $Entries - eventslists in array format */ function getEventList(&$calendar, $start_date, $end_date, $info = '') { global $log, $theme; $Entries = array(); $category = getParentTab(); global $adb, $current_user, $mod_strings, $app_strings, $cal_log, $listview_max_textlength, $list_max_entries_per_page; require 'user_privileges/user_privileges_' . $current_user->id . '.php'; require 'user_privileges/sharing_privileges_' . $current_user->id . '.php'; $cal_log->debug("Entering getEventList() method..."); $and = "AND (\n\t\t\t\t\t(\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t(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)\n\t\t\t\t\t\tAND vtiger_recurringevents.activityid is NULL\n\t\t\t\t\t)\n\t\t\t\tOR (\n\t\t\t\t\t\t(CAST(CONCAT(vtiger_recurringevents.recurringdate,' ',time_start) AS DATETIME) >= ?\n\t\t\t\t\t\t\tAND CAST(CONCAT(vtiger_recurringevents.recurringdate,' ',time_start) AS DATETIME) <= ?)\n\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\tOR\t(CAST(CONCAT(vtiger_recurringevents.recurringdate,' ',time_start) AS DATETIME) <= ?\n\t\t\t\t\t\t\tAND CAST(CONCAT(due_date,' ',time_end) AS DATETIME) >= ?)\n\t\t\t\t\t)\n\t\t\t\t)"; $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.smownerid, vtiger_crmentity.crmid,\n \t\tvtiger_activity.* FROM vtiger_activity\n\t\tINNER JOIN vtiger_crmentity\n\t\t\tON vtiger_crmentity.crmid = vtiger_activity.activityid\n\t\tLEFT JOIN vtiger_groups\n\t\t\tON vtiger_groups.groupid = vtiger_crmentity.smownerid\n\t\tLEFT JOIN vtiger_users\n\t \t\tON vtiger_users.id = vtiger_crmentity.smownerid \n\t\tLEFT OUTER JOIN vtiger_recurringevents\n\t\t\tON vtiger_recurringevents.activityid = vtiger_activity.activityid\n\t\tWHERE vtiger_crmentity.deleted = 0\n\t\t\tAND (vtiger_activity.activitytype not in ('Emails','Task')) {$and} "; $list_query = $query . " AND vtiger_crmentity.smownerid = " . $current_user->id; // User Select Customization: Changes should made also in (Appointment::readAppointment) $query_filter_prefix = calendarview_getSelectedUserFilterQuerySuffix(); $query .= $query_filter_prefix; $count_query .= $query_filter_prefix; // END $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(), $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(), $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue(), $startDate->getDBInsertDateTimeValue(), $endDate->getDBInsertDateTimeValue()); if ($info != '') { $groupids = explode(",", fetchUserGroupids($current_user->id)); // Explode can be removed, once implode is removed from fetchUserGroupids if (count($groupids) > 0) { $com_q = " AND (vtiger_crmentity.smownerid = ?\n\t\t\t\t\tOR vtiger_groups.groupid in (" . generateQuestionMarks($groupids) . "))\n\t\t\t\t\tGROUP BY vtiger_activity.activityid"; } else { $com_q = " AND vtiger_crmentity.smownerid = ?\n\t\t\t\tGROUP BY vtiger_activity.activityid"; } $pending_query = $query . " AND (vtiger_activity.eventstatus = 'Planned')" . $com_q; $total_q = $query . "" . $com_q; array_push($info_params, $current_user->id); if (count($groupids) > 0) { array_push($info_params, $groupids); } $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 getEventList() method..."); return array('totalevent' => $total, 'pendingevent' => $pending_rows); } if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[16] == 3) { $sec_parameter = getCalendarViewSecurityParameter(); $query .= $sec_parameter; } if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'search') { $search_where = calendar_search_where($_REQUEST['field_name'], $_REQUEST['search_option'], $_REQUEST['search_text']); $group_cond .= $search_where; } $group_cond .= " GROUP BY vtiger_activity.activityid ORDER BY vtiger_activity.date_start,vtiger_activity.time_start ASC"; //Ticket 6476 if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true) { $count_result = $adb->pquery(mkCountQuery($query), $params); $noofrows = $adb->query_result($count_result, 0, "count"); } else { $noofrows = null; } global $currentModule; $queryMode = isset($_REQUEST['query']) && $_REQUEST['query'] == 'true'; //$viewid is used as a key for cache query and other info so pass the dates as viewid $viewid = $start_date . $end_date; $start = ListViewSession::getRequestCurrentPage($currentModule, $adb->convert2sql($query, $params), $viewid, $queryMode); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); //end $start_rec = ($start - 1) * $list_max_entries_per_page; $end_rec = $navigation_array['end_val']; //print_r($navigation_array);die(); //echo $end_rec.'val'; $list_query = $adb->convert2Sql($query, $params); $_SESSION['Calendar_listquery'] = $list_query; if ($start_rec < 0) { $start_rec = 0; } $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(); $element['no'] = $c + 1; $image_tag = ""; $contact_data = ""; $more_link = ""; $start_time = $adb->query_result($result, $i, "time_start"); $end_time = $adb->query_result($result, $i, "time_end"); $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 . ' ' . $end_time); if (!empty($start_time)) { $start_time = $date->getDisplayTime(); } if (!empty($end_time)) { $end_time = $endDate->getDisplayTime(); } $format = $calendar['calendar']->hour_format; $value = getaddEventPopupTime($start_time, $end_time, $format); $start_hour = $value['starthour'] . ':' . $value['startmin'] . '' . $value['startfmt']; $end_hour = $value['endhour'] . ':' . $value['endmin'] . '' . $value['endfmt']; $element['starttime'] = $date->getDisplayDate() . ' ' . $start_hour; $element['endtime'] = $endDate->getDisplayDate() . ' ' . $end_hour; $contact_id = $adb->query_result($result, $i, "contactid"); $id = $adb->query_result($result, $i, "activityid"); $subject = $adb->query_result($result, $i, "subject"); $eventstatus = $adb->query_result($result, $i, "eventstatus"); $assignedto = $adb->query_result($result, $i, "user_name"); $userid = $adb->query_result($result, $i, "smownerid"); $idShared = "normal"; if (!empty($assignedto) && $userid != $current_user->id && $adb->query_result($result, $i, "visibility") == "Public") { $que = "select * from vtiger_sharedcalendar where sharedid=? and userid=?"; $row = $adb->pquery($que, array($current_user->id, $userid)); $no = $adb->getRowCount($row); if ($no > 0) { $idShared = "shared"; } else { $idShared = "normal"; } } if ($listview_max_textlength && strlen($subject) > $listview_max_textlength) { $subject = substr($subject, 0, $listview_max_textlength) . "..."; } if ($contact_id != '') { $displayValueArray = getEntityName('Contacts', $contact_id); if (!empty($displayValueArray)) { foreach ($displayValueArray as $key => $field_value) { $contactname = $field_value; } } $contact_data = "<b>" . $contactname . "</b>,"; } $more_link = "<a href='index.php?action=DetailView&module=Calendar&record=" . $id . "&activity_mode=Events&viewtype=calendar&parenttab=" . $category . "' class='webMnu'>[" . $mod_strings['LBL_MORE'] . "...]</a>"; $type = $adb->query_result($result, $i, "activitytype"); if ($type == 'Call') { $image_tag = "<img src='" . vtiger_imageurl('Calls.gif', $theme) . "' align='middle'> " . $app_strings['Call']; } else { if ($type == 'Meeting') { $image_tag = "<img src='" . vtiger_imageurl('Meetings.gif', $theme) . "' align='middle'> " . $app_strings['Meeting']; } else { $image_tag = " " . getTranslatedString($type); } } $element['eventtype'] = $image_tag; $element['eventdetail'] = $contact_data . " " . $subject . " " . $more_link; /*if(getFieldVisibilityPermission('Events',$current_user->id,'parent_id') == '0') { $element['relatedto']= getRelatedTo('Calendar',$result,$i); }*/ if ($idShared == "normal") { if (isPermitted("Calendar", "EditView") == "yes" || isPermitted("Calendar", "Delete") == "yes") { $element['action'] = "<img onClick='getcalAction(this,\"eventcalAction\"," . $id . ",\"" . $calendar['view'] . "\",\"" . $calendar['calendar']->date_time->hour . "\",\"" . $calendar['calendar']->date_time->get_DB_formatted_date() . "\",\"event\");' src='" . vtiger_imageurl('cal_event.jpg', $theme) . "' border='0'>"; } } else { if (isPermitted("Calendar", "EditView") == "yes" || isPermitted("Calendar", "Delete") == "yes") { $element['action'] = "<img onClick=\"alert('" . $mod_strings["SHARED_EVENT_DEL_MSG"] . "')\"; src='" . vtiger_imageurl('cal_event.jpg', $theme) . "' border='0'>"; } } if (getFieldVisibilityPermission('Events', $current_user->id, 'eventstatus') == '0') { if (!$is_admin && $eventstatus != '') { $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_eventstatus where eventstatus=?"; $res = $adb->pquery($sql, array(decode_html($eventstatus))); $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($eventstatus)); } else { $element['status'] = "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>"; } } else { $element['status'] = getTranslatedString(decode_html($eventstatus)); } } if (!empty($assignedto)) { $element['assignedto'] = $assignedto; } else { $element['assignedto'] = $adb->query_result($result, $i, "groupname"); } $element['visibility'] = $adb->query_result($result, $i, "visibility"); $c++; $Entries[] = $element; } $ret_arr[0] = $Entries; $ret_arr[1] = $navigation_array; $cal_log->debug("Exiting getEventList() method..."); return $ret_arr; }