pquery($query, array($id)); $rows = $adb->num_rows($result); for($j=0;$j<$rows;$j++) { $id = $adb->query_result($result,$j,'sharedid'); $sharedname = getFullNameFromQResult($result, $j, 'Users'); $sharedid[$id]=$sharedname; } return $sharedid; } /** * To get the lists of vtiger_users id who shared their calendar with specified user * @param $sharedid -- The shared user id :: Type integer * @returns $shared_ids -- a comma seperated vtiger_users id :: Type string */ function getSharedCalendarId($sharedid) { global $adb; $query = "SELECT * from vtiger_sharedcalendar where sharedid=?"; $result = $adb->pquery($query, array($sharedid)); if($adb->num_rows($result)!=0) { for($j=0;$j<$adb->num_rows($result);$j++) $userid[] = $adb->query_result($result,$j,'userid'); $shared_ids = implode (",",$userid); } return $shared_ids; } /** * To get userid and username of all vtiger_users except the current user * @param $id -- The user id :: Type integer * @returns $user_details -- Array in the following format: * $user_details=Array($userid1=>$username, $userid2=>$username,............,$useridn=>$username); */ function getOtherUserName($id) { global $adb; $user_details=Array(); $query="select * from vtiger_users where deleted=0 and status='Active' and id!=?"; $result = $adb->pquery($query, array($id)); $num_rows=$adb->num_rows($result); for($i=0;$i<$num_rows;$i++) { $userid=$adb->query_result($result,$i,'id'); $username = getFullNameFromQResult($result, $i, 'Users'); $user_details[$userid]=$username; } return $user_details; } /** * To get userid and username of vtiger_users in hierarchy level * @param $id -- The user id :: Type integer * @returns $user_details -- Array in the following format: * $user_details=Array($userid1=>$username, $userid2=>$username,............,$useridn=>$username); */ function getSharingUserName($id) { global $adb,$current_user; $user_details=Array(); $assigned_user_id = $current_user->id; require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); require('user_privileges/user_privileges_'.$current_user->id.'.php'); if($is_admin==false && $profileGlobalPermission[2] == 1 && ($defaultOrgSharingPermission[getTabid('Calendar')] == 3 or $defaultOrgSharingPermission[getTabid('Calendar')] == 0)) { $role_seq = implode($parent_roles, "::"); $query = "select id as id,user_name as user_name from vtiger_users where id=? and status='Active' union select vtiger_user2role.userid as id,vtiger_users.user_name as user_name from vtiger_user2role inner join vtiger_users on vtiger_users.id=vtiger_user2role.userid inner join vtiger_role on vtiger_role.roleid=vtiger_user2role.roleid where vtiger_role.parentrole like ? and status='Active' union select shareduserid as id,vtiger_users.user_name as user_name from vtiger_tmp_write_user_sharing_per inner join vtiger_users on vtiger_users.id=vtiger_tmp_write_user_sharing_per.shareduserid where status='Active' and vtiger_tmp_write_user_sharing_per.userid=? and vtiger_tmp_write_user_sharing_per.tabid=9"; $params = array($current_user->id, $role_seq."::%", $current_user->id); if (!empty($assigned_user_id)) { $query .= " OR id=?"; array_push($params, $assigned_user_id); } $query .= " order by user_name ASC"; $result = $adb->pquery($query, $params, true, "Error filling in user array: "); while($row = $adb->fetchByAssoc($result)) { $temp_result[$row['id']] = $row['user_name']; } $user_details = &$temp_result; unset($user_details[$id]); } else { $user_details = get_user_array(FALSE, "Active", $id); unset($user_details[$id]); } return $user_details; } /** * To get hour,minute and format * @param $starttime -- The date&time :: Type string * @param $endtime -- The date&time :: Type string * @param $format -- The format :: Type string * @returns $timearr :: Type Array */ function getaddEventPopupTime($starttime,$endtime,$format) { $timearr = Array(); list($sthr,$stmin) = explode(":",$starttime); list($edhr,$edmin) = explode(":",$endtime); if($format == 'am/pm') { $hr = $sthr+0; $timearr['startfmt'] = ($hr >= 12) ? "pm" : "am"; if($hr == 0) $hr = 12; $timearr['starthour'] = twoDigit(($hr>12)?($hr-12):$hr); $timearr['startmin'] = $stmin; $edhr = $edhr+0; $timearr['endfmt'] = ($edhr >= 12) ? "pm" : "am"; if($edhr == 0) $edhr = 12; $timearr['endhour'] = twoDigit(($edhr>12)?($edhr-12):$edhr); $timearr['endmin'] = $edmin; return $timearr; } if($format == '24') { $timearr['starthour'] = twoDigit($sthr); $timearr['startmin'] = $stmin; $timearr['startfmt'] = ''; $timearr['endhour'] = twoDigit($edhr); $timearr['endmin'] = $edmin; $timearr['endfmt'] = ''; return $timearr; } } /** *To construct time select combo box *@param $format -- the format :: Type string *@param $bimode -- The mode :: Type string *constructs html select combo box for time selection *and returns it in string format. */ function getTimeCombo($format,$bimode,$hour='',$min='',$fmt='',$todocheck=false) { global $mod_strings; $combo = ''; $min = $min - ($min%5); if($bimode == 'start' && !$todocheck) $jsfn = 'onChange="changeEndtime_StartTime(document.EditView.activitytype.value);"'; else $jsfn = null; if($format == 'am/pm') { $combo .= ' '; $combo .= ' '; $combo .= ''; } else { $combo .= ''.$mod_strings[LBL_HR].' '; $combo .= ' '.$mod_strings[LBL_MIN].''; } return $combo; } /** *Function to construct HTML select combo box *@param $fieldname -- the field name :: Type string *@param $tablename -- The table name :: Type string *constructs html select combo box for combo field *and returns it in string format. */ function getActFieldCombo($fieldname,$tablename) { global $adb, $mod_strings,$current_user; require('user_privileges/user_privileges_'.$current_user->id.'.php'); $combo = ''; $js_fn = ''; if($fieldname == 'eventstatus') $js_fn = 'onChange = "getSelectedStatus();"'; $combo .= ''; return $combo; } /*Fuction to get value for Assigned To field *returns values of Assigned To field in array format */ function getAssignedTo($tabid) { global $current_user,$noof_group_rows,$adb; $assigned_user_id = $current_user->id; require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); require('user_privileges/user_privileges_'.$current_user->id.'.php'); if($is_admin==false && $profileGlobalPermission[2] == 1 && ($defaultOrgSharingPermission[$tabid] == 3 or $defaultOrgSharingPermission[$tabid] == 0)) { $result=get_current_user_access_groups('Calendar'); } else { $result = get_group_options(); } if($result) $nameArray = $adb->fetch_array($result); if($is_admin==false && $profileGlobalPermission[2] == 1 && ($defaultOrgSharingPermission[$tabid] == 3 or $defaultOrgSharingPermission[$tabid] == 0)) { $users_combo = get_select_options_array(get_user_array(FALSE, "Active", $assigned_user_id,'private'), $assigned_user_id); } else { $users_combo = get_select_options_array(get_user_array(FALSE, "Active", $assigned_user_id), $assigned_user_id); } if($noof_group_rows!=0) { do { $groupname=$nameArray["groupname"]; $group_option[] = array($groupname=>$selected); }while($nameArray = $adb->fetch_array($result)); } $fieldvalue[]=$users_combo; $fieldvalue[] = $group_option; return $fieldvalue; } //Code Added by Minnie -Ends /** * Function to get the vtiger_activity details for mail body * @param string $description - activity description * @param string $from - to differenciate from notification to invitation. * return string $list - HTML in string format */ function getActivityDetails($description,$user_id,$from='') { global $log,$current_user,$current_language; global $adb; require_once 'include/utils/utils.php'; $mod_strings = return_module_language($current_language, 'Calendar'); $log->debug("Entering getActivityDetails(".$description.") method ..."); $updated = $mod_strings['LBL_UPDATED']; $created = $mod_strings['LBL_CREATED']; $reply = (($description['mode'] == 'edit')?"$updated":"$created"); if($description['activity_mode'] == "Events") { $end_date_lable=$mod_strings['End date and time']; } else { $end_date_lable=$mod_strings['Due Date']; } $name = getUserFullName($user_id); if($from == "invite") $msg = getTranslatedString($mod_strings['LBL_ACTIVITY_INVITATION']); else $msg = getTranslatedString($mod_strings['LBL_ACTIVITY_NOTIFICATION']); $current_username = getUserFullName($current_user->id); $status = getTranslatedString($description['status'],'Calendar'); $list = $name.','; $list .= '

'.$msg.' '.$reply.'.
'.$mod_strings['LBL_DETAILS_STRING'].':
'; $list .= '
      '.$mod_strings["LBL_SUBJECT"].' : '.$description['subject']; $list .= '
      '.$mod_strings["Start date and time"].' : '.$description['st_date_time'] .' '.DateTimeField::getDBTimeZone(); $list .= '
      '.$end_date_lable.' : '.$description['end_date_time'].' '.DateTimeField::getDBTimeZone(); $list .= '
      '.$mod_strings["LBL_STATUS"].': '.$status; $list .= '
      '.$mod_strings["Priority"].': '.getTranslatedString($description['taskpriority']); $list .= '
      '.$mod_strings["Related To"].': '.getTranslatedString($description['relatedto']); if(!empty($description['contact_name'])) { $list .= '
      '.$mod_strings["LBL_CONTACT_LIST"].' '.$description['contact_name']; } else $list .= '
      '.$mod_strings["Location"].' : '.$description['location']; $list .= '
      '.$mod_strings["LBL_APP_DESCRIPTION"].': '.$description['description']; $list .= '

'.$mod_strings["LBL_REGARDS_STRING"].' ,'; $list .= '
'.$current_username.'.'; $log->debug("Exiting getActivityDetails method ..."); return $list; } function twoDigit( $no ){ if($no < 10 && strlen(trim($no)) < 2) return "0".$no; else return "".$no; } function timeString($datetime,$fmt){ $timeStr = formatUserTimeString($datetime, $fmt); $date = new DateTimeField($timeStr); list($h, $m) = explode(':', $date->getDisplayTime()); $timeStr = formatUserTimeString(array('hour'=>$h, 'minute'=>$m), $fmt); return $timeStr; } /** * * @param type $datetime * @param type $fmt * @return Date */ function formatUserTimeString($datetime,$fmt){ if(is_object($datetime)){ $hr = $datetime->hour; $min = $datetime->minute; } else { $hr = $datetime['hour']; $min = $datetime['minute']; } $timeStr = ""; if($fmt != 'am/pm'){ $timeStr .= twoDigit($hr).":".twoDigit($min); }else{ $am_pm = array('AM', 'PM'); $hour = twoDigit($hr%12); if($hour == 0) { $hour = 12; } $timeStr = $hour.':'.twoDigit($min).$am_pm[($hr/12)%2]; } return $timeStr; } function sendInvitation($inviteesid,$mode,$subject,$desc) { global $current_user,$mod_strings; require_once("modules/Emails/mail.php"); $invites=$mod_strings['INVITATION']; $invitees_array = explode(';',$inviteesid); $subject = $invites.' : '.$subject; $record = $focus->id; foreach($invitees_array as $inviteeid) { if($inviteeid != '') { $description=getActivityDetails($desc,$inviteeid,"invite"); $to_email = getUserEmailId('id',$inviteeid); send_mail('Calendar',$to_email,$current_user->user_name,'',$subject,$description); } } } function getActivityMailInfo($return_id,$status,$activity_type) { $mail_data = Array(); global $adb; $qry = "select * from vtiger_activity where activityid=?"; $ary_res = $adb->pquery($qry, array($return_id)); $send_notification = $adb->query_result($ary_res,0,"sendnotification"); $subject = $adb->query_result($ary_res,0,"subject"); $priority = $adb->query_result($ary_res,0,"priority"); $st_date = $adb->query_result($ary_res,0,"date_start"); $st_time = $adb->query_result($ary_res,0,"time_start"); $end_date = $adb->query_result($ary_res,0,"due_date"); $end_time = $adb->query_result($ary_res,0,"time_end"); $location = $adb->query_result($ary_res,0,"location"); if(!empty($st_time)){ $date = new DateTimeField($st_date.' '.$st_time); $st_date = $date->getDisplayDate(); $st_time = $date->getDisplayTime(); } if(!empty($end_time)){ $date = new DateTimeField($end_date.' '.$end_time); $end_date = $date->getDisplayDate(); $end_time = $date->getDisplayTime(); } $owner_qry = "select smownerid from vtiger_crmentity where crmid=?"; $res = $adb->pquery($owner_qry, array($return_id)); $owner_id = $adb->query_result($res,0,"smownerid"); $usr_res = $adb->pquery("select count(*) as count from vtiger_users where id=?",array($owner_id)); if($adb->query_result($usr_res, 0, 'count')>0) { $assignType = "U"; $usr_id = $owner_id; } else { $assignType = "T"; $group_qry = "select groupname from vtiger_groups where groupid=?"; $grp_res = $adb->pquery($group_qry, array($owner_id)); $grp_name = $adb->query_result($grp_res,0,"groupname"); } $desc_qry = "select description from vtiger_crmentity where crmid=?"; $des_res = $adb->pquery($desc_qry, array($return_id)); $description = $adb->query_result($des_res,0,"description"); $rel_qry = "select case vtiger_crmentity.setype when 'Leads' then vtiger_leaddetails.lastname when 'Accounts' then vtiger_account.accountname when 'Potentials' then vtiger_potential.potentialname when 'Quotes' then vtiger_quotes.subject when 'PurchaseOrder' then vtiger_purchaseorder.subject when 'SalesOrder' then vtiger_salesorder.subject when 'Invoice' then vtiger_invoice.subject when 'Campaigns' then vtiger_campaign.campaignname when 'HelpDesk' then vtiger_troubletickets.title end as relname from vtiger_seactivityrel inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_seactivityrel.crmid left join vtiger_leaddetails on vtiger_leaddetails.leadid = vtiger_seactivityrel.crmid left join vtiger_account on vtiger_account.accountid=vtiger_seactivityrel.crmid left join vtiger_potential on vtiger_potential.potentialid=vtiger_seactivityrel.crmid left join vtiger_quotes on vtiger_quotes.quoteid= vtiger_seactivityrel.crmid left join vtiger_purchaseorder on vtiger_purchaseorder.purchaseorderid = vtiger_seactivityrel.crmid left join vtiger_salesorder on vtiger_salesorder.salesorderid = vtiger_seactivityrel.crmid left join vtiger_invoice on vtiger_invoice.invoiceid = vtiger_seactivityrel.crmid left join vtiger_campaign on vtiger_campaign.campaignid = vtiger_seactivityrel.crmid left join vtiger_troubletickets on vtiger_troubletickets.ticketid = vtiger_seactivityrel.crmid where vtiger_seactivityrel.activityid=?"; $rel_res = $adb->pquery($rel_qry, array($return_id)); $rel_name = $adb->query_result($rel_res,0,"relname"); $relatedContacts = getActivityRelatedContacts($return_id); $mail_data['mode'] = "edit"; $mail_data['activity_mode'] = $activity_type; $mail_data['sendnotification'] = $send_notification; $mail_data['user_id'] = $usr_id; $mail_data['subject'] = $subject; $mail_data['status'] = $status; $mail_data['taskpriority'] = $priority; $mail_data['relatedto'] = $rel_name; $mail_data['contact_name'] = implode(',', $relatedContacts); $mail_data['description'] = $description; $mail_data['assign_type'] = $assignType; $mail_data['group_name'] = $grp_name; $value = getaddEventPopupTime($st_time,$end_time,'24'); $start_hour = $value['starthour'].':'.$value['startmin'].''.$value['startfmt']; if($activity_type != 'Task' ) $end_hour = $value['endhour'] .':'.$value['endmin'].''.$value['endfmt']; $date = new DateTimeField($st_date." ".$start_hour); $endDate = new DateTimeField($end_date." ".$end_hour); $mail_data['st_date_time'] = $date->getDBInsertDateTimeValue(); $mail_data['end_date_time'] = $endDate->getDBInsertDateValue().' '. $endDate->getDBInsertTimeValue(); $mail_data['location']=$location; return $mail_data; } // User Select Customization /** * Function returns the id of the User selected by current user in the picklist of the ListView or Calendar view of Current User * return String - Id of the user that the current user has selected */ function calendarview_getSelectedUserId() { global $current_user, $default_charset; $only_for_user = htmlspecialchars(strip_tags($_REQUEST['onlyforuser']),ENT_QUOTES,$default_charset); if($only_for_user == '') $only_for_user = $current_user->id; return $only_for_user; } 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 returns the data of the user selected by current user in the picklist of the ListView or Calendar view of Current User * @param $useridInUse - The Id of the user that the Current User has selected in dropdown picklist in Calendar modules listview or Calendar View * return string - The array of the events for the user that the current user has selected */ function calendarview_getUserSelectOptions($useridInUse) { global $adb, $app_strings, $current_user, $mod_strings; $users = $adb->query("SELECT id,user_name FROM vtiger_users WHERE status = 'Active' and deleted = 0"); $userscount = $adb->num_rows($users); $userSelectdata = "" . $app_strings['LBL_LIST_OF'] . " : "; $userSelectdata .=""; return $userSelectdata; } // END ?>