From 792f4d82f9e7e05f0256841871ddeda749e14141 Mon Sep 17 00:00:00 2001 From: YuCheng Hu Date: Mon, 15 Nov 2010 09:48:27 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=B0=205.2=20=E6=AD=A3?= =?UTF-8?q?=E5=BC=8F=E7=89=88=E5=90=8E=E7=AC=AC=E4=B8=80=E6=AC=A1=20SVN=20?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit yuchenghu@hawebs.net git-svn-id: https://svn.code.sf.net/p/hawebs/svn@582 a2543c7e-f6e9-4f8a-8bff-1ffc34733512 --- .../trunk/modules/Calendar/Activity.php | 1016 ++++++++ .../trunk/modules/Calendar/ActivityAjax.php | 239 ++ .../Calendar/ActivityReminderCallbackAjax.php | 139 ++ .../ActivityReminderSetupCallbackAjax.php | 46 + .../trunk/modules/Calendar/Appointment.php | 292 +++ oss/vtiger/trunk/modules/Calendar/Calendar.js | 123 + .../trunk/modules/Calendar/Calendar.php | 297 +++ .../trunk/modules/Calendar/CalendarAjax.php | 13 + .../trunk/modules/Calendar/CalendarCommon.php | 608 +++++ .../trunk/modules/Calendar/CustomView.php | 14 + oss/vtiger/trunk/modules/Calendar/Date.php | 511 ++++ oss/vtiger/trunk/modules/Calendar/Delete.php | 36 + .../trunk/modules/Calendar/DetailView.php | 359 +++ .../trunk/modules/Calendar/EditView.php | 297 +++ .../trunk/modules/Calendar/ListView.php | 282 +++ .../modules/Calendar/ListViewPagging.php | 11 + .../trunk/modules/Calendar/OpenListView.php | 210 ++ .../trunk/modules/Calendar/QuickCreate.php | 19 + .../modules/Calendar/RenderRelatedListUI.php | 164 ++ .../trunk/modules/Calendar/RepeatEvents.php | 186 ++ oss/vtiger/trunk/modules/Calendar/Save.php | 305 +++ .../trunk/modules/Calendar/SendReminder.bat | 3 + .../trunk/modules/Calendar/Settings.php | 42 + .../trunk/modules/Calendar/TagCloud.php | 12 + .../trunk/modules/Calendar/TodoSave.php | 85 + .../trunk/modules/Calendar/UnifiedSearch.php | 11 + .../trunk/modules/Calendar/addEventUI.php | 1106 +++++++++ .../trunk/modules/Calendar/calendarLayout.php | 2183 +++++++++++++++++ .../trunk/modules/Calendar/calendar_share.php | 169 ++ .../modules/Calendar/disable_sharing.php | 22 + oss/vtiger/trunk/modules/Calendar/header.php | 120 + .../Calendar/iCal/iCalendar_components.php | 628 +++++ .../Calendar/iCal/iCalendar_parameters.php | 227 ++ .../Calendar/iCal/iCalendar_properties.php | 1367 +++++++++++ .../Calendar/iCal/iCalendar_rfc2445.php | 807 ++++++ .../Calendar/iCal/ical-parser-class.php | 91 + .../trunk/modules/Calendar/iCalExport.php | 113 + .../trunk/modules/Calendar/iCalImport.php | 146 ++ oss/vtiger/trunk/modules/Calendar/index.php | 32 + .../modules/Calendar/language/en_us.lang.php | 452 ++++ .../modules/Calendar/language/zh_cn.lang.php | 453 ++++ .../trunk/modules/Calendar/new_calendar.php | 92 + oss/vtiger/trunk/modules/Calendar/script.js | 1400 +++++++++++ .../Calendar/updateCalendarSharing.php | 45 + .../modules/Calendar/updateRelations.php | 64 + 45 files changed, 14837 insertions(+) create mode 100644 oss/vtiger/trunk/modules/Calendar/Activity.php create mode 100644 oss/vtiger/trunk/modules/Calendar/ActivityAjax.php create mode 100644 oss/vtiger/trunk/modules/Calendar/ActivityReminderCallbackAjax.php create mode 100644 oss/vtiger/trunk/modules/Calendar/ActivityReminderSetupCallbackAjax.php create mode 100644 oss/vtiger/trunk/modules/Calendar/Appointment.php create mode 100644 oss/vtiger/trunk/modules/Calendar/Calendar.js create mode 100644 oss/vtiger/trunk/modules/Calendar/Calendar.php create mode 100644 oss/vtiger/trunk/modules/Calendar/CalendarAjax.php create mode 100644 oss/vtiger/trunk/modules/Calendar/CalendarCommon.php create mode 100644 oss/vtiger/trunk/modules/Calendar/CustomView.php create mode 100644 oss/vtiger/trunk/modules/Calendar/Date.php create mode 100644 oss/vtiger/trunk/modules/Calendar/Delete.php create mode 100644 oss/vtiger/trunk/modules/Calendar/DetailView.php create mode 100644 oss/vtiger/trunk/modules/Calendar/EditView.php create mode 100644 oss/vtiger/trunk/modules/Calendar/ListView.php create mode 100644 oss/vtiger/trunk/modules/Calendar/ListViewPagging.php create mode 100644 oss/vtiger/trunk/modules/Calendar/OpenListView.php create mode 100644 oss/vtiger/trunk/modules/Calendar/QuickCreate.php create mode 100644 oss/vtiger/trunk/modules/Calendar/RenderRelatedListUI.php create mode 100644 oss/vtiger/trunk/modules/Calendar/RepeatEvents.php create mode 100644 oss/vtiger/trunk/modules/Calendar/Save.php create mode 100644 oss/vtiger/trunk/modules/Calendar/SendReminder.bat create mode 100644 oss/vtiger/trunk/modules/Calendar/Settings.php create mode 100644 oss/vtiger/trunk/modules/Calendar/TagCloud.php create mode 100644 oss/vtiger/trunk/modules/Calendar/TodoSave.php create mode 100644 oss/vtiger/trunk/modules/Calendar/UnifiedSearch.php create mode 100644 oss/vtiger/trunk/modules/Calendar/addEventUI.php create mode 100644 oss/vtiger/trunk/modules/Calendar/calendarLayout.php create mode 100644 oss/vtiger/trunk/modules/Calendar/calendar_share.php create mode 100644 oss/vtiger/trunk/modules/Calendar/disable_sharing.php create mode 100644 oss/vtiger/trunk/modules/Calendar/header.php create mode 100644 oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_components.php create mode 100644 oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_parameters.php create mode 100644 oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_properties.php create mode 100644 oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_rfc2445.php create mode 100644 oss/vtiger/trunk/modules/Calendar/iCal/ical-parser-class.php create mode 100644 oss/vtiger/trunk/modules/Calendar/iCalExport.php create mode 100644 oss/vtiger/trunk/modules/Calendar/iCalImport.php create mode 100644 oss/vtiger/trunk/modules/Calendar/index.php create mode 100644 oss/vtiger/trunk/modules/Calendar/language/en_us.lang.php create mode 100644 oss/vtiger/trunk/modules/Calendar/language/zh_cn.lang.php create mode 100644 oss/vtiger/trunk/modules/Calendar/new_calendar.php create mode 100644 oss/vtiger/trunk/modules/Calendar/script.js create mode 100644 oss/vtiger/trunk/modules/Calendar/updateCalendarSharing.php create mode 100644 oss/vtiger/trunk/modules/Calendar/updateRelations.php diff --git a/oss/vtiger/trunk/modules/Calendar/Activity.php b/oss/vtiger/trunk/modules/Calendar/Activity.php new file mode 100644 index 00000000..ce8d1dd7 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/Activity.php @@ -0,0 +1,1016 @@ +'crmid','vtiger_activity'=>'activityid','vtiger_seactivityrel'=>'activityid','vtiger_cntactivityrel'=>'activityid','vtiger_salesmanactivityrel'=>'activityid','vtiger_activity_reminder'=>'activity_id','vtiger_recurringevents'=>'activityid','vtiger_activitycf'=>'activityid'); + + var $column_fields = Array(); + var $sortby_fields = Array('subject','due_date','date_start','smownerid','activitytype','lastname'); //Sorting is added for due date and start date + + // This is used to retrieve related vtiger_fields from form posts. + var $additional_column_fields = Array('assigned_user_name', 'assigned_user_id', 'contactname', 'contact_phone', 'contact_email', 'parent_name'); + + /** + * Mandatory table for supporting custom fields. + */ + var $customFieldTable = Array('vtiger_activitycf', 'activityid'); + + // This is the list of vtiger_fields that are in the lists. + var $list_fields = Array( + 'Close'=>Array('activity'=>'status'), + 'Type'=>Array('activity'=>'activitytype'), + 'Subject'=>Array('activity'=>'subject'), + 'Related to'=>Array('seactivityrel'=>'parent_id'), + 'Start Date'=>Array('activity'=>'date_start'), + 'Start Time'=>Array('activity','time_start'), + 'End Date'=>Array('activity'=>'due_date'), + 'End Time'=>Array('activity','time_end'), + 'Recurring Type'=>Array('recurringevents'=>'recurringtype'), + 'Assigned To'=>Array('crmentity'=>'smownerid'), + 'Contact Name'=>Array('contactdetails'=>'lastname') + ); + + var $range_fields = Array( + 'name', + 'date_modified', + 'start_date', + 'id', + 'status', + 'date_due', + 'time_start', + 'description', + 'contact_name', + 'priority', + 'duehours', + 'dueminutes', + 'location' + ); + + + var $list_fields_name = Array( + 'Close'=>'status', + 'Type'=>'activitytype', + 'Subject'=>'subject', + 'Contact Name'=>'lastname', + 'Related to'=>'parent_id', + 'Start Date & Time'=>'date_start', + 'End Date & Time'=>'due_date', + 'Recurring Type'=>'recurringtype', + 'Assigned To'=>'assigned_user_id'); + + var $list_link_field= 'subject'; + + //Added these variables which are used as default order by and sortorder in ListView + var $default_order_by = 'due_date'; + var $default_sort_order = 'ASC'; + + //var $groupTable = Array('vtiger_activitygrouprelation','activityid'); + + function Activity() { + $this->log = LoggerManager::getLogger('Calendar'); + $this->db = PearDatabase::getInstance(); + $this->column_fields = getColumnFields('Calendar'); + } + + function save_module($module) + { + global $adb; + //Handling module specific save + //Insert into seactivity rel + if(isset($this->column_fields['parent_id']) && $this->column_fields['parent_id'] != '') + { + $this->insertIntoEntityTable("vtiger_seactivityrel", $module); + } + elseif($this->column_fields['parent_id']=='' && $insertion_mode=="edit") + { + $this->deleteRelation("vtiger_seactivityrel"); + } + //Insert into cntactivity rel + if(isset($this->column_fields['contact_id']) && $this->column_fields['contact_id'] != '') + { + $this->insertIntoEntityTable('vtiger_cntactivityrel', $module); + } + elseif($this->column_fields['contact_id'] =='' && $insertion_mode=="edit") + { + $this->deleteRelation('vtiger_cntactivityrel'); + } + if(isset($this->column_fields['sendnotification'])){ + + $mail_data = Array(); + $mail_data['user_id'] = $this->column_fields['assigned_user_id']; + $mail_data['subject'] = $this->column_fields['subject']; + $mail_data['status'] = (($this->column_fields['activitytype']=='Task')?($this->column_fields['taskstatus']):($this->column_fields['eventstatus'])); + $mail_data['taskpriority'] = $this->column_fields['taskpriority']; + $mail_data['contact_name'] = $this->column_fields['contact_id']; + $mail_data['description'] = $this->column_fields['description']; + $value = getaddEventPopupTime($this->column_fields['time_start'],$this->column_fields['time_end'],'24'); + $start_hour = $value['starthour'].':'.$value['startmin'].''.$value['startfmt']; + $mail_data['st_date_time'] = getDisplayDate($this->column_fields['date_start'])." ".$start_hour; + $mail_data['end_date_time']=getDisplayDate($this->column_fields['due_date']); + getEventNotification($this->column_fields['activitytype'],$this->column_fields['subject'],$mail_data); + + } + $recur_type=''; + if(($recur_type == "--None--" || $recur_type == '') && $this->mode == "edit") + { + $sql = 'delete from vtiger_recurringevents where activityid=?'; + $adb->pquery($sql, array($this->id)); + } + //Handling for recurring type + //Insert into vtiger_recurring event table + if(isset($this->column_fields['recurringtype']) && $this->column_fields['recurringtype']!='' && $this->column_fields['recurringtype']!='--None--') + { + $recur_type = trim($this->column_fields['recurringtype']); + $recur_data = getrecurringObjValue(); + if(is_object($recur_data)) + $this->insertIntoRecurringTable($recur_data); + } + + //Insert into vtiger_activity_remainder table + + $this->insertIntoReminderTable('vtiger_activity_reminder',$module,""); + + //Handling for invitees + $selected_users_string = $_REQUEST['inviteesid']; + $invitees_array = explode(';',$selected_users_string); + $this->insertIntoInviteeTable($module,$invitees_array); + + //Inserting into sales man activity rel + $this->insertIntoSmActivityRel($module); + + $this->insertIntoActivityReminderPopup($module); + } + + + /** Function to insert values in vtiger_activity_reminder_popup table for the specified module + * @param $cbmodule -- module:: Type varchar + */ + function insertIntoActivityReminderPopup($cbmodule) { + + global $adb; + + $cbrecord = $this->id; + unset($_SESSION['next_reminder_time']); + if(isset($cbmodule) && isset($cbrecord)) { + $cbdate = getValidDBInsertDateValue($this->column_fields['date_start']); + $cbtime = $this->column_fields['time_start']; + + $reminder_query = "SELECT reminderid FROM vtiger_activity_reminder_popup WHERE semodule = ? and recordid = ?"; + $reminder_params = array($cbmodule, $cbrecord); + $reminderidres = $adb->pquery($reminder_query, $reminder_params); + + $reminderid = null; + if($adb->num_rows($reminderidres) > 0) { + $reminderid = $adb->query_result($reminderidres, 0, "reminderid"); + } + + if(isset($reminderid)) { + $callback_query = "UPDATE vtiger_activity_reminder_popup set status = 0, date_start = ?, time_start = ? WHERE reminderid = ?"; + $callback_params = array($cbdate, $cbtime, $reminderid); + } else { + $callback_query = "INSERT INTO vtiger_activity_reminder_popup (recordid, semodule, date_start, time_start) VALUES (?,?,?,?)"; + $callback_params = array($cbrecord, $cbmodule, $cbdate, $cbtime); + } + + $adb->pquery($callback_query, $callback_params); + } + } + + + /** Function to insert values in vtiger_activity_remainder table for the specified module, + * @param $table_name -- table name:: Type varchar + * @param $module -- module:: Type varchar + */ + function insertIntoReminderTable($table_name,$module,$recurid) + { + global $log; + $log->info("in insertIntoReminderTable ".$table_name." module is ".$module); + if($_REQUEST['set_reminder'] == 'Yes') + { + unset($_SESSION['next_reminder_time']); + $log->debug("set reminder is set"); + $rem_days = $_REQUEST['remdays']; + $log->debug("rem_days is ".$rem_days); + $rem_hrs = $_REQUEST['remhrs']; + $log->debug("rem_hrs is ".$rem_hrs); + $rem_min = $_REQUEST['remmin']; + $log->debug("rem_minutes is ".$rem_min); + $reminder_time = $rem_days * 24 * 60 + $rem_hrs * 60 + $rem_min; + $log->debug("reminder_time is ".$reminder_time); + if ($recurid == "") + { + if($_REQUEST['mode'] == 'edit') + { + $this->activity_reminder($this->id,$reminder_time,0,$recurid,'edit'); + } + else + { + $this->activity_reminder($this->id,$reminder_time,0,$recurid,''); + } + } + else + { + $this->activity_reminder($this->id,$reminder_time,0,$recurid,''); + } + } + elseif($_REQUEST['set_reminder'] == 'No') + { + $this->activity_reminder($this->id,'0',0,$recurid,'delete'); + } + } + + + // Code included by Jaguar - starts + /** Function to insert values in vtiger_recurringevents table for the specified tablename,module + * @param $recurObj -- Recurring Object:: Type varchar + */ +function insertIntoRecurringTable(& $recurObj) +{ + global $log,$adb; + $log->info("in insertIntoRecurringTable "); + $st_date = $recurObj->startdate->get_formatted_date(); + $log->debug("st_date ".$st_date); + $end_date = $recurObj->enddate->get_formatted_date(); + $log->debug("end_date is set ".$end_date); + $type = $recurObj->recur_type; + $log->debug("type is ".$type); + $flag="true"; + + if($_REQUEST['mode'] == 'edit') + { + $activity_id=$this->id; + + $sql='select min(recurringdate) AS min_date,max(recurringdate) AS max_date, recurringtype, activityid from vtiger_recurringevents where activityid=? group by activityid, recurringtype'; + $result = $adb->pquery($sql, array($activity_id)); + $noofrows = $adb->num_rows($result); + for($i=0; $i<$noofrows; $i++) + { + $recur_type_b4_edit = $adb->query_result($result,$i,"recurringtype"); + $date_start_b4edit = $adb->query_result($result,$i,"min_date"); + $end_date_b4edit = $adb->query_result($result,$i,"max_date"); + } + if(($st_date == $date_start_b4edit) && ($end_date==$end_date_b4edit) && ($type == $recur_type_b4_edit)) + { + if($_REQUEST['set_reminder'] == 'Yes') + { + $sql = 'delete from vtiger_activity_reminder where activity_id=?'; + $adb->pquery($sql, array($activity_id)); + $sql = 'delete from vtiger_recurringevents where activityid=?'; + $adb->pquery($sql, array($activity_id)); + $flag="true"; + } + elseif($_REQUEST['set_reminder'] == 'No') + { + $sql = 'delete from vtiger_activity_reminder where activity_id=?'; + $adb->pquery($sql, array($activity_id)); + $flag="false"; + } + else + $flag="false"; + } + else + { + $sql = 'delete from vtiger_activity_reminder where activity_id=?'; + $adb->pquery($sql, array($activity_id)); + $sql = 'delete from vtiger_recurringevents where activityid=?'; + $adb->pquery($sql, array($activity_id)); + } + } + $date_array = $recurObj->recurringdates; + if(isset($recurObj->recur_freq) && $recurObj->recur_freq != null) + $recur_freq = $recurObj->recur_freq; + else + $recur_freq = 1; + if($recurObj->recur_type == 'Daily' || $recurObj->recur_type == 'Yearly') + $recurringinfo = $recurObj->recur_type; + elseif($recurObj->recur_type == 'Weekly') + { + $recurringinfo = $recurObj->recur_type; + if($recurObj->dayofweek_to_rpt != null) + $recurringinfo = $recurringinfo.'::'.implode('::',$recurObj->dayofweek_to_rpt); + } + elseif($recurObj->recur_type == 'Monthly') + { + $recurringinfo = $recurObj->recur_type.'::'.$recurObj->repeat_monthby; + if($recurObj->repeat_monthby == 'date') + $recurringinfo = $recurringinfo.'::'.$recurObj->rptmonth_datevalue; + else + $recurringinfo = $recurringinfo.'::'.$recurObj->rptmonth_daytype.'::'.$recurObj->dayofweek_to_rpt[0]; + } + else + { + $recurringinfo = ''; + } + if($flag=="true") + { + for($k=0; $k< count($date_array); $k++) + { + $tdate=$date_array[$k]; + if($tdate <= $end_date) + { + $max_recurid_qry = 'select max(recurringid) AS recurid from vtiger_recurringevents;'; + $result = $adb->pquery($max_recurid_qry, array()); + $noofrows = $adb->num_rows($result); + for($i=0; $i<$noofrows; $i++) + { + $recur_id = $adb->query_result($result,$i,"recurid"); + } + $current_id =$recur_id+1; + $recurring_insert = "insert into vtiger_recurringevents values (?,?,?,?,?,?)"; + $rec_params = array($current_id, $this->id, $tdate, $type, $recur_freq, $recurringinfo); + $adb->pquery($recurring_insert, $rec_params); + unset($_SESSION['next_reminder_time']); + if($_REQUEST['set_reminder'] == 'Yes') + { + $this->insertIntoReminderTable("vtiger_activity_reminder",$module,$current_id,''); + } + } + } + } +} + + + /** Function to insert values in vtiger_invitees table for the specified module,tablename ,invitees_array + * @param $table_name -- table name:: Type varchar + * @param $module -- module:: Type varchar + * @param $invitees_array Array + */ + function insertIntoInviteeTable($module,$invitees_array) + { + global $log,$adb; + $log->debug("Entering insertIntoInviteeTable(".$module.",".$invitees_array.") method ..."); + if($this->mode == 'edit'){ + $sql = "delete from vtiger_invitees where activityid=?"; + $adb->pquery($sql, array($this->id)); + } + foreach($invitees_array as $inviteeid) + { + if($inviteeid != '') + { + $query="insert into vtiger_invitees values(?,?)"; + $adb->pquery($query, array($this->id, $inviteeid)); + } + } + $log->debug("Exiting insertIntoInviteeTable method ..."); + + } + + + /** Function to insert values in vtiger_salesmanactivityrel table for the specified module + * @param $module -- module:: Type varchar + */ + + function insertIntoSmActivityRel($module) + { + global $adb; + global $current_user; + if($this->mode == 'edit'){ + $sql = "delete from vtiger_salesmanactivityrel where activityid=?"; + $adb->pquery($sql, array($this->id)); + } + + $user_sql = $adb->pquery("select count(*) as count from vtiger_users where id=?", array($this->column_fields['assigned_user_id'])); + if($adb->query_result($user_sql, 0, 'count') != 0) { + $sql_qry = "insert into vtiger_salesmanactivityrel (smid,activityid) values(?,?)"; + $adb->pquery($sql_qry, array($this->column_fields['assigned_user_id'], $this->id)); + + if(isset($_REQUEST['inviteesid']) && $_REQUEST['inviteesid']!='') + { + $selected_users_string = $_REQUEST['inviteesid']; + $invitees_array = explode(';',$selected_users_string); + foreach($invitees_array as $inviteeid) + { + if($inviteeid != '') + { + $resultcheck = $adb->pquery("select * from vtiger_salesmanactivityrel where activityid=? and smid=?",array($this->id,$inviteeid)); + if($adb->num_rows($resultcheck) != 1){ + $query="insert into vtiger_salesmanactivityrel values(?,?)"; + $adb->pquery($query, array($inviteeid, $this->id)); + } + } + } + } + } +} + + + // Mike Crowe Mod --------------------------------------------------------Default ordering for us + /** + * Function to get sort order + * return string $sorder - sortorder string either 'ASC' or 'DESC' + */ + function getSortOrder() + { + global $log; + $log->debug("Entering getSortOrder() method ..."); + if(isset($_REQUEST['sorder'])) + $sorder = $this->db->sql_escape_string($_REQUEST['sorder']); + else + $sorder = (($_SESSION['ACTIVITIES_SORT_ORDER'] != '')?($_SESSION['ACTIVITIES_SORT_ORDER']):($this->default_sort_order)); + $log->debug("Exiting getSortOrder method ..."); + return $sorder; + } + + /** + * Function to get order by + * return string $order_by - fieldname(eg: 'subject') + */ + function getOrderBy() + { + global $log; + $log->debug("Entering getOrderBy() method ..."); + + $use_default_order_by = ''; + if(PerformancePrefs::getBoolean('LISTVIEW_DEFAULT_SORTING', true)) { + $use_default_order_by = $this->default_order_by; + } + + if (isset($_REQUEST['order_by'])) + $order_by = $this->db->sql_escape_string($_REQUEST['order_by']); + else + $order_by = (($_SESSION['ACTIVITIES_ORDER_BY'] != '')?($_SESSION['ACTIVITIES_ORDER_BY']):($use_default_order_by)); + $log->debug("Exiting getOrderBy method ..."); + return $order_by; + } + // Mike Crowe Mod -------------------------------------------------------- + + + +//Function Call for Related List -- Start + /** + * Function to get Activity related Contacts + * @param integer $id - activityid + * returns related Contacts record in array format + */ + function get_contacts($id, $cur_tab_id, $rel_tab_id, $actions=false) { + global $log, $singlepane_view,$currentModule,$current_user; + $log->debug("Entering get_contacts(".$id.") method ..."); + $this_module = $currentModule; + + $related_module = vtlib_getModuleNameById($rel_tab_id); + require_once("modules/$related_module/$related_module.php"); + $other = new $related_module(); + vtlib_setup_modulevars($related_module, $other); + $singular_modname = vtlib_toSingular($related_module); + + $parenttab = getParentTab(); + + $returnset = '&return_module='.$this_module.'&return_action=DetailView&activity_mode=Events&return_id='.$id; + + $search_string = ''; + $button = ''; + + if($actions) { + if(is_string($actions)) $actions = explode(',', strtoupper($actions)); + if(in_array('SELECT', $actions) && isPermitted($related_module,4, '') == 'yes') { + $button .= " "; + } + } + + $query = 'select vtiger_users.user_name,vtiger_contactdetails.accountid,vtiger_contactdetails.contactid, vtiger_contactdetails.firstname,vtiger_contactdetails.lastname, vtiger_contactdetails.department, vtiger_contactdetails.title, vtiger_contactdetails.email, vtiger_contactdetails.phone, vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime from vtiger_contactdetails inner join vtiger_cntactivityrel on vtiger_cntactivityrel.contactid=vtiger_contactdetails.contactid inner join vtiger_crmentity on vtiger_crmentity.crmid = vtiger_contactdetails.contactid left join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid left join vtiger_groups on vtiger_groups.groupid = vtiger_crmentity.smownerid where vtiger_cntactivityrel.activityid='.$id.' and vtiger_crmentity.deleted=0'; + + $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset); + + if($return_value == null) $return_value = Array(); + $return_value['CUSTOM_BUTTON'] = $button; + + $log->debug("Exiting get_contacts method ..."); + return $return_value; + } + + /** + * Function to get Activity related Users + * @param integer $id - activityid + * returns related Users record in array format + */ + + function get_users($id) { + global $log; + $log->debug("Entering get_contacts(".$id.") method ..."); + global $app_strings; + + $focus = new Users(); + + $button = ''; + + $returnset = '&return_module=Calendar&return_action=CallRelatedList&return_id='.$id; + + $query = 'SELECT vtiger_users.id, vtiger_users.first_name,vtiger_users.last_name, vtiger_users.user_name, vtiger_users.email1, vtiger_users.email2, vtiger_users.status, vtiger_users.is_admin, vtiger_user2role.roleid, vtiger_users.yahoo_id, vtiger_users.phone_home, vtiger_users.phone_work, vtiger_users.phone_mobile, vtiger_users.phone_other, vtiger_users.phone_fax,vtiger_activity.date_start,vtiger_activity.due_date,vtiger_activity.time_start,vtiger_activity.duration_hours,vtiger_activity.duration_minutes from vtiger_users inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.smid=vtiger_users.id inner join vtiger_activity on vtiger_activity.activityid=vtiger_salesmanactivityrel.activityid inner join vtiger_user2role on vtiger_user2role.userid=vtiger_users.id where vtiger_activity.activityid='.$id; + + $return_data = GetRelatedList('Calendar','Users',$focus,$query,$button,$returnset); + + if($return_data == null) $return_data = Array(); + $return_data['CUSTOM_BUTTON'] = $button; + + $log->debug("Exiting get_users method ..."); + return $return_data; + } + + /** + * Function to get activities for given criteria + * @param string $criteria - query string + * returns activity records in array format($list) or null value + */ + function get_full_list($criteria) { + global $log; + $log->debug("Entering get_full_list(".$criteria.") method ..."); + $query = "select vtiger_crmentity.crmid,vtiger_crmentity.smownerid,vtiger_crmentity.setype, vtiger_activity.*, + vtiger_contactdetails.lastname, vtiger_contactdetails.firstname, vtiger_contactdetails.contactid + from vtiger_activity + inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid + left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid + left join vtiger_contactdetails on vtiger_contactdetails.contactid= vtiger_cntactivityrel.contactid + left join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid + WHERE vtiger_crmentity.deleted=0 ".$criteria; + $result =& $this->db->query($query); + + if($this->db->getRowCount($result) > 0){ + + // We have some data. + while ($row = $this->db->fetchByAssoc($result)) { + foreach($this->list_fields_name as $field) + { + if (isset($row[$field])) { + $this->$field = $row[$field]; + } + else { + $this->$field = ''; + } + } + $list[] = $this; + } + } + if (isset($list)) + { + $log->debug("Exiting get_full_list method ..."); + return $list; + } + else + { + $log->debug("Exiting get_full_list method ..."); + return null; + } + + } + + +//calendarsync + /** + * Function to get meeting count + * @param string $user_name - User Name + * return integer $row["count(*)"] - count + */ + function getCount_Meeting($user_name) + { + global $log; + $log->debug("Entering getCount_Meeting(".$user_name.") method ..."); + $query = "select count(*) from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid where user_name=? and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Meeting'"; + $result = $this->db->pquery($query, array($user_name),true,"Error retrieving contacts count"); + $rows_found = $this->db->getRowCount($result); + $row = $this->db->fetchByAssoc($result, 0); + $log->debug("Exiting getCount_Meeting method ..."); + return $row["count(*)"]; + } + + function get_calendars($user_name,$from_index,$offset) + { + global $log; + $log->debug("Entering get_calendars(".$user_name.",".$from_index.",".$offset.") method ..."); + $query = "select vtiger_activity.location as location,vtiger_activity.duration_hours as duehours, vtiger_activity.duration_minutes as dueminutes,vtiger_activity.time_start as time_start, vtiger_activity.subject as name,vtiger_crmentity.modifiedtime as date_modified, vtiger_activity.date_start start_date,vtiger_activity.activityid as id,vtiger_activity.status as status, vtiger_crmentity.description as description, vtiger_activity.priority as vtiger_priority, vtiger_activity.due_date as date_due ,vtiger_contactdetails.firstname cfn, vtiger_contactdetails.lastname cln from vtiger_activity inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Meeting' limit " .$from_index ."," .$offset; + $log->debug("Exiting get_calendars method ..."); + return $this->process_list_query1($query); + } +//calendarsync + /** + * Function to get task count + * @param string $user_name - User Name + * return integer $row["count(*)"] - count + */ + function getCount($user_name) + { + global $log; + $log->debug("Entering getCount(".$user_name.") method ..."); + $query = "select count(*) from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid where user_name=? and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Task'"; + $result = $this->db->pquery($query,array($user_name), true,"Error retrieving contacts count"); + $rows_found = $this->db->getRowCount($result); + $row = $this->db->fetchByAssoc($result, 0); + + $log->debug("Exiting getCount method ..."); + return $row["count(*)"]; + } + + /** + * Function to get list of task for user with given limit + * @param string $user_name - User Name + * @param string $from_index - query string + * @param string $offset - query string + * returns tasks in array format + */ + function get_tasks($user_name,$from_index,$offset) + { + global $log; + $log->debug("Entering get_tasks(".$user_name.",".$from_index.",".$offset.") method ..."); + $query = "select vtiger_activity.subject as name,vtiger_crmentity.modifiedtime as date_modified, vtiger_activity.date_start start_date,vtiger_activity.activityid as id,vtiger_activity.status as status, vtiger_crmentity.description as description, vtiger_activity.priority as priority, vtiger_activity.due_date as date_due ,vtiger_contactdetails.firstname cfn, vtiger_contactdetails.lastname cln from vtiger_activity inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid where user_name='" .$user_name ."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Task' limit " .$from_index ."," .$offset; + $log->debug("Exiting get_tasks method ..."); + return $this->process_list_query1($query); + + } + + /** + * Function to process the activity list query + * @param string $query - query string + * return array $response - activity lists + */ + function process_list_query1($query) + { + global $log; + $log->debug("Entering process_list_query1(".$query.") method ..."); + $result =& $this->db->query($query,true,"Error retrieving $this->object_name list: "); + $list = Array(); + $rows_found = $this->db->getRowCount($result); + if($rows_found != 0) + { + $task = Array(); + for($index = 0 , $row = $this->db->fetchByAssoc($result, $index); $row && $index <$rows_found;$index++, $row = $this->db->fetchByAssoc($result, $index)) + + { + foreach($this->range_fields as $columnName) + { + if (isset($row[$columnName])) { + + $task[$columnName] = $row[$columnName]; + } + else + { + $task[$columnName] = ""; + } + } + + $task[contact_name] = return_name($row, 'cfn', 'cln'); + + $list[] = $task; + } + } + + $response = Array(); + $response['list'] = $list; + $response['row_count'] = $rows_found; + $response['next_offset'] = $next_offset; + $response['previous_offset'] = $previous_offset; + + + $log->debug("Exiting process_list_query1 method ..."); + return $response; + } + + /** + * Function to get reminder for activity + * @param integer $activity_id - activity id + * @param string $reminder_time - reminder time + * @param integer $reminder_sent - 0 or 1 + * @param integer $recurid - recuring eventid + * @param string $remindermode - string like 'edit' + */ + function activity_reminder($activity_id,$reminder_time,$reminder_sent=0,$recurid,$remindermode='') + { + global $log; + $log->debug("Entering vtiger_activity_reminder(".$activity_id.",".$reminder_time.",".$reminder_sent.",".$recurid.",".$remindermode.") method ..."); + //Check for vtiger_activityid already present in the reminder_table + $query_exist = "SELECT activity_id FROM ".$this->reminder_table." WHERE activity_id = ?"; + $result_exist = $this->db->pquery($query_exist, array($activity_id)); + + if($remindermode == 'edit') + { + if($this->db->num_rows($result_exist) > 0) + { + $query = "UPDATE ".$this->reminder_table." SET"; + $query .=" reminder_sent = ?, reminder_time = ? WHERE activity_id =?"; + $params = array($reminder_sent, $reminder_time, $activity_id); + } + else + { + $query = "INSERT INTO ".$this->reminder_table." VALUES (?,?,?,?)"; + $params = array($activity_id, $reminder_time, 0, $recurid); + } + } + elseif(($remindermode == 'delete') && ($this->db->num_rows($result_exist) > 0)) + { + $query = "DELETE FROM ".$this->reminder_table." WHERE activity_id = ?"; + $params = array($activity_id); + } + else + { + $query = "INSERT INTO ".$this->reminder_table." VALUES (?,?,?,?)"; + $params = array($activity_id, $reminder_time, 0, $recurid); + } + $this->db->pquery($query,$params,true,"Error in processing vtiger_table $this->reminder_table"); + $log->debug("Exiting vtiger_activity_reminder method ..."); + } + + //Used for vtigerCRM Outlook Add-In + /** + * Function to get tasks to display in outlookplugin + * @param string $username - User name + * return string $query - sql query + */ + function get_tasksforol($username) + { + global $log,$adb; + $log->debug("Entering get_tasksforol(".$username.") method ..."); + global $current_user; + require_once("modules/Users/Users.php"); + $seed_user=new Users(); + $user_id=$seed_user->retrieve_user_id($username); + $current_user=$seed_user; + $current_user->retrieve_entity_info($user_id, 'Users'); + require('user_privileges/user_privileges_'.$current_user->id.'.php'); + require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); + + if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) + { + $sql1 = "select tablename,columnname from vtiger_field where tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.presence in (0,2)"; + $params1 = array(); + }else + { + $profileList = getCurrentUserProfileList(); + $sql1 = "select tablename,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; + $params1 = array(); + if (count($profileList) > 0) { + $sql1 .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")"; + array_push($params1, $profileList); + } + } + $result1 = $adb->pquery($sql1,$params1); + for($i=0;$i < $adb->num_rows($result1);$i++) + { + $permitted_lists[] = $adb->query_result($result1,$i,'tablename'); + $permitted_lists[] = $adb->query_result($result1,$i,'columnname'); + /*if($adb->query_result($result1,$i,'columnname') == "parentid") + { + $permitted_lists[] = 'vtiger_account'; + $permitted_lists[] = 'accountname'; + }*/ + } + $permitted_lists = array_chunk($permitted_lists,2); + $column_table_lists = array(); + for($i=0;$i < count($permitted_lists);$i++) + { + $column_table_lists[] = implode(".",$permitted_lists[$i]); + } + + $query = "select vtiger_activity.activityid as taskid, ".implode(',',$column_table_lists)." from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid + inner join vtiger_users on vtiger_users.id = vtiger_crmentity.smownerid + left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid + left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid + left join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid + where vtiger_users.user_name='".$username."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Task'"; + $log->debug("Exiting get_tasksforol method ..."); + return $query; + } + + /** + * Function to get calendar query for outlookplugin + * @param string $username - User name * return string $query - sql query */ + function get_calendarsforol($user_name) + { + global $log,$adb; + $log->debug("Entering get_calendarsforol(".$user_name.") method ..."); + global $current_user; + require_once("modules/Users/Users.php"); + $seed_user=new Users(); + $user_id=$seed_user->retrieve_user_id($user_name); + $current_user=$seed_user; + $current_user->retrieve_entity_info($user_id, 'Users'); + require('user_privileges/user_privileges_'.$current_user->id.'.php'); + require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); + + if($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) + { + $sql1 = "select tablename,columnname from vtiger_field where tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.presence in (0,2)"; + $params1 = array(); + }else + { + $profileList = getCurrentUserProfileList(); + $sql1 = "select tablename,columnname from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid=9 and tablename <> 'vtiger_recurringevents' and tablename <> 'vtiger_activity_reminder' and vtiger_field.displaytype in (1,2,4,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; + $params1 = array(); + if (count($profileList) > 0) { + $sql1 .= " and vtiger_profile2field.profileid in (". generateQuestionMarks($profileList) .")"; + array_push($params1,$profileList); + } + } + $result1 = $adb->pquery($sql1, $params1); + for($i=0;$i < $adb->num_rows($result1);$i++) + { + $permitted_lists[] = $adb->query_result($result1,$i,'tablename'); + $permitted_lists[] = $adb->query_result($result1,$i,'columnname'); + if($adb->query_result($result1,$i,'columnname') == "date_start") + { + $permitted_lists[] = 'vtiger_activity'; + $permitted_lists[] = 'time_start'; + } + if($adb->query_result($result1,$i,'columnname') == "due_date") + { + $permitted_lists[] = 'vtiger_activity'; + $permitted_lists[] = 'time_end'; + } + } + $permitted_lists = array_chunk($permitted_lists,2); + $column_table_lists = array(); + for($i=0;$i < count($permitted_lists);$i++) + { + $column_table_lists[] = implode(".",$permitted_lists[$i]); + } + + $query = "select vtiger_activity.activityid as clndrid, ".implode(',',$column_table_lists)." from vtiger_activity + inner join vtiger_salesmanactivityrel on vtiger_salesmanactivityrel.activityid=vtiger_activity.activityid + inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid + left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid=vtiger_activity.activityid + left join vtiger_contactdetails on vtiger_contactdetails.contactid=vtiger_cntactivityrel.contactid + left join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid + inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid + where vtiger_users.user_name='".$user_name."' and vtiger_crmentity.deleted=0 and vtiger_activity.activitytype='Meeting'"; + $log->debug("Exiting get_calendarsforol method ..."); + return $query; + } + + // Function to unlink all the dependent entities of the given Entity by Id + function unlinkDependencies($module, $id) { + global $log; + + $sql = 'DELETE FROM vtiger_activity_reminder WHERE activity_id=?'; + $this->db->pquery($sql, array($id)); + + $sql = 'DELETE FROM vtiger_recurringevents WHERE activityid=?'; + $this->db->pquery($sql, array($id)); + + parent::unlinkDependencies($module, $id); + } + + // Function to unlink an entity with given Id from another entity + function unlinkRelationship($id, $return_module, $return_id) { + global $log; + if(empty($return_module) || empty($return_id)) return; + + if($return_module == 'Contacts') { + $sql = 'DELETE FROM vtiger_cntactivityrel WHERE contactid = ? AND activityid = ?'; + $this->db->pquery($sql, array($return_id, $id)); + } elseif($return_module == 'HelpDesk') { + $sql = 'DELETE FROM vtiger_seactivityrel WHERE crmid = ? AND activityid = ?'; + $this->db->pquery($sql, array($return_id, $id)); + } else { + $sql='DELETE FROM vtiger_seactivityrel WHERE activityid=?'; + $this->db->pquery($sql, array($id)); + + $sql = 'DELETE FROM vtiger_crmentityrel WHERE (crmid=? AND relmodule=? AND relcrmid=?) OR (relcrmid=? AND module=? AND crmid=?)'; + $params = array($id, $return_module, $return_id, $id, $return_module, $return_id); + $this->db->pquery($sql, $params); + } + } + + /** + * this function sets the status flag of activity to true or false depending on the status passed to it + * @param string $status - the status of the activity flag to set + * @return:: true if successful; false otherwise + */ + function setActivityReminder($status){ + global $adb; + if($status == "on"){ + $flag = 0; + }elseif($status == "off"){ + $flag = 1; + }else{ + return false; + } + $sql = "update vtiger_activity_reminder_popup set status=1 where recordid=?"; + $adb->pquery($sql, array($this->id)); + return true; + } + + /* + * Function to get the relation tables for related modules + * @param - $secmodule secondary module name + * returns the array with table names and fieldnames storing relations between module and this module + */ + function setRelationTables($secmodule){ + $rel_tables = array ( + "Contacts" => array("vtiger_cntactivityrel"=>array("activityid","contactid"),"vtiger_activity"=>"activityid"), + "Leads" => array("vtiger_seactivityrel"=>array("activityid","crmid"),"vtiger_activity"=>"activityid"), + "Accounts" => array("vtiger_seactivityrel"=>array("activityid","crmid"),"vtiger_activity"=>"activityid"), + "Potentials" => array("vtiger_seactivityrel"=>array("activityid","crmid"),"vtiger_activity"=>"activityid"), + ); + return $rel_tables[$secmodule]; + } + + /* + * Function to get the secondary query part of a report + * @param - $module primary module name + * @param - $secmodule secondary module name + * returns the query string formed on fetching the related data for report for secondary module + */ + function generateReportsSecQuery($module,$secmodule){ + $query = $this->getRelationQuery($module,$secmodule,"vtiger_activity","activityid"); + $query .=" left join vtiger_crmentity as vtiger_crmentityCalendar on vtiger_crmentityCalendar.crmid=vtiger_activity.activityid and vtiger_crmentityCalendar.deleted=0 + left join vtiger_cntactivityrel on vtiger_cntactivityrel.activityid= vtiger_activity.activityid + left join vtiger_contactdetails as vtiger_contactdetailsCalendar on vtiger_contactdetailsCalendar.contactid= vtiger_cntactivityrel.contactid + left join vtiger_activitycf on vtiger_activitycf.activityid = vtiger_crmentity.crmid + left join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid + left join vtiger_activity_reminder on vtiger_activity_reminder.activity_id = vtiger_activity.activityid + left join vtiger_recurringevents on vtiger_recurringevents.activityid = vtiger_activity.activityid + left join vtiger_crmentity as vtiger_crmentityRelCalendar on vtiger_crmentityRelCalendar.crmid = vtiger_seactivityrel.crmid and vtiger_crmentityRelCalendar.deleted=0 + left join vtiger_account as vtiger_accountRelCalendar on vtiger_accountRelCalendar.accountid=vtiger_crmentityRelCalendar.crmid + left join vtiger_leaddetails as vtiger_leaddetailsRelCalendar on vtiger_leaddetailsRelCalendar.leadid = vtiger_crmentityRelCalendar.crmid + left join vtiger_potential as vtiger_potentialRelCalendar on vtiger_potentialRelCalendar.potentialid = vtiger_crmentityRelCalendar.crmid + left join vtiger_quotes as vtiger_quotesRelCalendar on vtiger_quotesRelCalendar.quoteid = vtiger_crmentityRelCalendar.crmid + left join vtiger_purchaseorder as vtiger_purchaseorderRelCalendar on vtiger_purchaseorderRelCalendar.purchaseorderid = vtiger_crmentityRelCalendar.crmid + left join vtiger_invoice as vtiger_invoiceRelCalendar on vtiger_invoiceRelCalendar.invoiceid = vtiger_crmentityRelCalendar.crmid + left join vtiger_salesorder as vtiger_salesorderRelCalendar on vtiger_salesorderRelCalendar.salesorderid = vtiger_crmentityRelCalendar.crmid + left join vtiger_troubletickets as vtiger_troubleticketsRelCalendar on vtiger_troubleticketsRelCalendar.ticketid = vtiger_crmentityRelCalendar.crmid + left join vtiger_campaign as vtiger_campaignRelCalendar on vtiger_campaignRelCalendar.campaignid = vtiger_crmentityRelCalendar.crmid + left join vtiger_groups as vtiger_groupsCalendar on vtiger_groupsCalendar.groupid = vtiger_crmentityCalendar.smownerid + left join vtiger_users as vtiger_usersCalendar on vtiger_usersCalendar.id = vtiger_crmentityCalendar.smownerid"; + return $query; + } + + public function getNonAdminAccessControlQuery($module, $user,$scope='') { + require('user_privileges/user_privileges_'.$user->id.'.php'); + require('user_privileges/sharing_privileges_'.$user->id.'.php'); + $query = ' '; + $tabId = getTabid($module); + if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] + == 1 && $defaultOrgSharingPermission[$tabId] == 3) { + $tableName = 'vt_tmp_u'.$user->id.'_t'.$tabId; + $sharingRuleInfoVariable = $module.'_share_read_permission'; + $sharingRuleInfo = $$sharingRuleInfoVariable; + $sharedTabId = null; + $this->setupTemporaryTable($tableName, $sharedTabId, $user, + $current_user_parent_role_seq, $current_user_groups); + $query = " INNER JOIN $tableName $tableName$scope ON ($tableName$scope.id = ". + "vtiger_crmentity$scope.smownerid and $tableName$scope.shared=0) "; + $sharedIds = getSharedCalendarId($user->id); + if(!empty($sharedIds)){ + $query .= "or ($tableName$scope.id = vtiger_crmentity$scope.smownerid AND ". + "$tableName$scope.shared=1 and vtiger_activity$scope.visibility = 'Public') "; + } + } + return $query; + } + + protected function setupTemporaryTable($tableName, $tabId, $user, $parentRole, $userGroups) { + $module = null; + if (!empty($tabId)) { + $module = getTabname($tabId); + } + $query = $this->getNonAdminAccessQuery($module, $user, $parentRole, $userGroups); + $query = "create temporary table IF NOT EXISTS $tableName(id int(11) primary key, shared ". + "int(1) default 0) ignore ".$query; + $db = PearDatabase::getInstance(); + $result = $db->pquery($query, array()); + if(is_object($result)) { + $query = "create temporary table IF NOT EXISTS $tableName(id int(11) primary key, shared ". + "int(1) default 0) replace select 1, userid as id from vtiger_sharedcalendar where ". + "sharedid = $user->id"; + $result = $db->pquery($query, array()); + if(is_object($result)) { + return true; + } + } + return false; + } +} +?> diff --git a/oss/vtiger/trunk/modules/Calendar/ActivityAjax.php b/oss/vtiger/trunk/modules/Calendar/ActivityAjax.php new file mode 100644 index 00000000..650a151e --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/ActivityAjax.php @@ -0,0 +1,239 @@ +debug("In CalendarAjax file"); +$mysel = vtlib_purify($_REQUEST['view']); +if($_REQUEST['file'] == 'OpenListView') +{ + require_once('Smarty_setup.php'); + $smarty = new vtigerCRM_Smarty; + require_once("modules/Calendar/OpenListView.php"); + $smarty->assign("APP",$app_strings); + $smarty->assign("IMAGE_PATH",$image_path); + if($_REQUEST['mode'] == '0') + { + $activities[0] = getPendingActivities(0); + $smarty->assign("ACTIVITIES",$activities); + $smarty->display("upcomingActivities.tpl"); + } + else if($_REQUEST['mode'] == '1') + { + $activities[1] = getPendingActivities(1); + $smarty->assign("ACTIVITIES",$activities); + $smarty->display("pendingActivities.tpl"); + } + die(); +} +$calendar_arr = Array(); +$calendar_arr['IMAGE_PATH'] = $image_path; +$date_data = array(); +if ( isset($_REQUEST['day'])) +{ + $date_data['day'] = $_REQUEST['day']; +} +if ( isset($_REQUEST['month'])) +{ + $date_data['month'] = $_REQUEST['month']; +} +if ( isset($_REQUEST['week'])) +{ + $date_data['week'] = $_REQUEST['week']; +} +if ( isset($_REQUEST['year'])) +{ + if ($_REQUEST['year'] > 2037 || $_REQUEST['year'] < 1970) + { + print("".$app_strings['LBL_CAL_LIMIT_MSG'].""); + exit; + } + $date_data['year'] = $_REQUEST['year']; +} + + +if((isset($_REQUEST['type']) && $_REQUEST['type'] !='') || (isset($_REQUEST['n_type']) && $_REQUEST['n_type'] !='')) +{ + $type = $_REQUEST['type']; + $n_type = $_REQUEST['n_type']; + $cal_log->debug("type value is:".$type); + if($type == 'minical') + { + $cal_log->debug("going to get mini calendar"); + $temp_module = $currentModule; + $mod_strings = return_module_language($current_language,'Calendar'); + $currentModule = 'Calendar'; + $calendar_arr['IMAGE_PATH'] = $image_path; + $calendar_arr['calendar'] = new Calendar('month',$date_data); + $calendar_arr['view'] = 'month'; + $calendar_arr['size'] = 'small'; + if($current_user->hour_format != '') + $calendar_arr['calendar']->hour_format=$current_user->hour_format; + $calendar_arr['calendar']->add_Activities($current_user); + calendar_layout($calendar_arr); + $mod_strings = return_module_language($current_language,$temp_module); + $currentModule = vtlib_purify($_REQUEST['module']); + } + elseif($type == 'settings') + { + $cal_log->debug("going to get calendar Settings"); + require_once('modules/Calendar/calendar_share.php'); + } + else + { + $subtab = vtlib_purify($_REQUEST['subtab']); + if(empty($mysel)) + { + $mysel = 'day'; + } + $calendar_arr['calendar'] = new Calendar($mysel,$date_data); + + $calendar_arr['view'] = $mysel; + if($calendar_arr['calendar']->view == 'day') + $start_date = $end_date = $calendar_arr['calendar']->date_time->get_formatted_date(); + elseif($calendar_arr['calendar']->view == 'week') + { + $start_date = $calendar_arr['calendar']->slices[0]; + $end_date = $calendar_arr['calendar']->slices[6]; + } + elseif($calendar_arr['calendar']->view == 'month') + { + $start_date = $calendar_arr['calendar']->date_time->getThismonthDaysbyIndex(0); + $end_date = $calendar_arr['calendar']->date_time->getThismonthDaysbyIndex($calendar_arr['calendar']->date_time->daysinmonth - 1); + $start_date = $start_date->get_formatted_date(); + $end_date = $end_date->get_formatted_date(); + } + elseif($calendar_arr['calendar']->view == 'year') + { + $start_date = $calendar_arr['calendar']->date_time->getThisyearMonthsbyIndex(0); + $end_date = $calendar_arr['calendar']->date_time->get_first_day_of_changed_year('increment'); + $start_date = $start_date->get_formatted_date(); + $end_date = $end_date->get_formatted_date(); + } + else + { + die("view:".$calendar_arr['calendar']->view." is not defined"); + } + + if($type == 'change_owner' || $type == 'activity_delete' || $type == 'change_status' || $type == 'activity_postpone' || $n_type == 'nav') + { + if($current_user->hour_format != '') + $calendar_arr['calendar']->hour_format=$current_user->hour_format; + + if($type == 'change_status') + { + $return_id = vtlib_purify($_REQUEST['record']); + if(isset($_REQUEST['status'])) + { + $status = $_REQUEST['status']; + $activity_type = "Task"; + } + elseif(isset($_REQUEST['eventstatus'])) + { + $status = $_REQUEST['eventstatus']; + $activity_type = "Events"; + } + ChangeStatus($status,$return_id,$activity_type); + $mail_data = getActivityMailInfo($return_id,$status,$activity_type); + if($mail_data['sendnotification'] == 1) + { + getEventNotification($activity_type,$mail_data['subject'],$mail_data); + } + $invitee_qry = "select * from vtiger_invitees where activityid=?"; + $invitee_res = $adb->pquery($invitee_qry, array($return_id)); + $count = $adb->num_rows($invitee_res); + if($count != 0) + { + for($j = 0; $j < $count; $j++) + { + $invitees_ids[]= $adb->query_result($invitee_res,$j,"inviteeid"); + + } + $invitees_ids_string = implode(';',$invitees_ids); + sendInvitation($invitees_ids_string,$activity_type,$mail_data['subject'],$mail_data); + } + } + if($type == 'activity_postpone') + { + } + if ($_REQUEST['viewOption'] == 'hourview' && ($mysel == 'day' || $mysel == 'week' || $mysel == 'month' || $mysel == 'year')) + { + $calendar_arr['calendar']->add_Activities($current_user); + } + + if(isset($_REQUEST['viewOption']) && $_REQUEST['viewOption'] != null && $subtab == 'event') + { + if($_REQUEST['viewOption'] == 'hourview') + { + $cal_log->debug("going to get calendar Event HourView"); + if($calendar_arr['view'] == 'day') + { + echo getDayViewLayout($calendar_arr)."####".getEventInfo($calendar_arr,'listcnt'); + } + elseif($calendar_arr['view'] == 'week') + { + echo getWeekViewLayout($calendar_arr)."####".getEventInfo($calendar_arr,'listcnt'); + } + elseif($calendar_arr['view'] == 'month') + { + echo getMonthViewLayout($calendar_arr)."####".getEventInfo($calendar_arr,'listcnt'); + } + elseif($calendar_arr['view'] == 'year') + { + echo getYearViewLayout($calendar_arr)."####".getEventInfo($calendar_arr,'listcnt'); + } + else + { + die("view:".$view['view']." is not defined"); + } + } + elseif($_REQUEST['viewOption'] == 'listview') + { + $cal_log->debug("going to get calendar Event ListView"); + //To get Events List + $activity_arr = getEventList($calendar_arr, $start_date, $end_date); + $activity_list = $activity_arr[0]; + $navigation_arr = $activity_arr[1]; + echo constructEventListView($calendar_arr,$activity_list,$navigation_arr)."####".getEventInfo($calendar_arr,'listcnt'); + } + } + elseif($subtab == 'todo') + { + $cal_log->debug("going to get calendar Todo ListView"); + //To get Todos List + $todo_arr = getTodoList($calendar_arr, $start_date, $end_date); + $todo_list = $todo_arr[0]; + $navigation_arr = $todo_arr[1]; + echo constructTodoListView($todo_list,$calendar_arr,$subtab,$navigation_arr)."####".getTodoInfo($calendar_arr,'listcnt'); + } + } + elseif($type == 'view') + { + checkFileAccess('modules/Calendar/'.$_REQUEST['file'].'.php'); + require_once('modules/Calendar/'.$_REQUEST['file'].'.php'); + } + else + { + die("View option is not defined"); + } + } +} +else +{ + require_once('include/Ajax/CommonAjax.php'); + //die("type is not set"); +} + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/ActivityReminderCallbackAjax.php b/oss/vtiger/trunk/modules/Calendar/ActivityReminderCallbackAjax.php new file mode 100644 index 00000000..7e666d5e --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/ActivityReminderCallbackAjax.php @@ -0,0 +1,139 @@ + $cur_time)) { + echo ""; + return; +} +$log = LoggerManager::getLogger('Activity_Reminder'); +$smarty = new vtigerCRM_Smarty; +if(isPermitted('Calendar','index') == 'yes'){ + $active = $adb->pquery("select * from vtiger_users where id=?",array($current_user->id)); + $active_res = $adb->query_result($active,0,'reminder_interval'); + if($active_res == 'None') { + $_SESSION['next_reminder_time'] = 'None'; + } + if($active_res!='None'){ + $interval=$adb->query_result($active,0,"reminder_interval"); + $intervalInMinutes = ConvertToMinutes($interval); + // check for reminders every minute + $time = time(); + $_SESSION['next_reminder_time'] = $time + ($intervalInMinutes * 60); + $date = date('Y-m-d', strtotime("+$intervalInMinutes minutes", $time)); + $time = date('H:i', strtotime("+$intervalInMinutes minutes", $time)); + $callback_query = + "SELECT * FROM vtiger_activity_reminder_popup inner join vtiger_crmentity where " . + " vtiger_activity_reminder_popup.status = 0 and " . + " vtiger_activity_reminder_popup.recordid = vtiger_crmentity.crmid " . + " and vtiger_crmentity.smownerid = ".$current_user->id." and vtiger_crmentity.deleted = 0 " . + " and ((DATE_FORMAT(vtiger_activity_reminder_popup.date_start,'%Y-%m-%d') < '" . $date . "')" . + " OR ((DATE_FORMAT(vtiger_activity_reminder_popup.date_start,'%Y-%m-%d') = '" . $date . "')" . + " AND (TIME_FORMAT(vtiger_activity_reminder_popup.time_start,'%H:%i') <= '" . $time . "')))"; + + $result = $adb->query($callback_query); + + $cbrows = $adb->num_rows($result); + if($cbrows > 0) { + for($index = 0; $index < $cbrows; ++$index) { + $reminderid = $adb->query_result($result, $index, "reminderid"); + $cbrecord = $adb->query_result($result, $index, "recordid"); + $cbmodule = $adb->query_result($result, $index, "semodule"); + + $focus = CRMEntity::getInstance($cbmodule); + + if($cbmodule == 'Calendar') { + $focus->retrieve_entity_info($cbrecord,$cbmodule); + + $cbsubject = $focus->column_fields['subject']; + $cbactivitytype = $focus->column_fields['activitytype']; + $cbdate = $focus->column_fields["date_start"]; + $cbtime = $focus->column_fields["time_start"]; + } else { + // For non-calendar records. + $cbsubject = array_values(getEntityName($cbmodule, $cbrecord)); + $cbsubject = $cbsubject[0]; + $cbactivitytype = getTranslatedString($cbmodule, $cbmodule); + $cbdate = $adb->query_result($result, $index, 'date_start'); + $cbtime = $adb->query_result($result, $index, 'time_start'); + } + + if($cbactivitytype=='Task') + $cbstatus = $focus->column_fields["taskstatus"]; + else + $cbstatus = $focus->column_fields["eventstatus"]; + // Appending recordid we can get unique callback dom id for that record. + $popupid = "ActivityReminder_$cbrecord"; + if($cbdate <= date('Y-m-d')){ + if($cbdate == date('Y-m-d') && $cbtime > date('H:i')) $cbcolor = ''; + else $cbcolor= '#FF1515'; + } + $smarty->assign("THEME", $theme); + $smarty->assign("popupid", $popupid); + $smarty->assign("APP", $app_strings); + $smarty->assign("cbreminderid", $reminderid); + $smarty->assign("cbdate", $cbdate); + $smarty->assign("cbtime", $cbtime); + $smarty->assign("cbsubject", $cbsubject); + $smarty->assign("cbmodule", $cbmodule); + $smarty->assign("cbrecord", $cbrecord); + $smarty->assign("cbstatus", $cbstatus); + $smarty->assign("cbcolor", $cbcolor); + $smarty->assign("cblinkdtl", $cblinkdtl); + $smarty->assign("activitytype", $cbactivitytype); + $smarty->display("ActivityReminderCallback.tpl"); + + $mark_reminder_as_read = "UPDATE vtiger_activity_reminder_popup set status = 1 where reminderid = ?"; + $adb->pquery($mark_reminder_as_read, array($reminderid)); + echo ""; + } + } else { + $callback_query = + "SELECT * FROM vtiger_activity_reminder_popup inner join vtiger_crmentity where " . + " vtiger_activity_reminder_popup.status = 0 and " . + " vtiger_activity_reminder_popup.recordid = vtiger_crmentity.crmid " . + " and vtiger_crmentity.smownerid = ".$current_user->id." and vtiger_crmentity.deleted = 0 ". + "AND vtiger_activity_reminder_popup.reminderid > 0 ORDER BY date_start DESC , ". + "TIME_FORMAT(vtiger_activity_reminder_popup.time_start,'%H:%i') DESC LIMIT 1"; + $result = $adb->query($callback_query); + $it = new SqlResultIterator($adb, $result); + $nextReminderTime = null; + foreach ($it as $row) { + $nextReminderTime = strtotime($row->date_start.' '.$row->time_start); + } + $_SESSION['next_reminder_time'] = $nextReminderTime - ($intervalInMinutes * 60); + } + echo ""; + } +} + +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/ActivityReminderSetupCallbackAjax.php b/oss/vtiger/trunk/modules/Calendar/ActivityReminderSetupCallbackAjax.php new file mode 100644 index 00000000..0d24f948 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/ActivityReminderSetupCallbackAjax.php @@ -0,0 +1,46 @@ +pquery($reminder_query, array($reminderid, $cbmodule, $cbrecord)); + echo ":#:SUCCESS"; + } else { + echo ":#:FAILURE"; + } + } +} + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/Appointment.php b/oss/vtiger/trunk/modules/Calendar/Appointment.php new file mode 100644 index 00000000..2f815452 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/Appointment.php @@ -0,0 +1,292 @@ +participant = Array(); + $this->participant_state = Array(); + $this->description = ""; + } + + /** To get the events of the specified user and shared events + * @param $userid -- The user Id:: Type integer + * @param $from_datetime -- The start date Obj :: Type Array + * @param $to_datetime -- The end date Obj :: Type Array + * @param $view -- The calendar view :: Type String + * @returns $list :: Type Array + */ + + function readAppointment($userid, &$from_datetime, &$to_datetime, $view) + { + global $current_user,$adb; + require('user_privileges/user_privileges_'.$current_user->id.'.php'); + require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); + $and = "AND ((vtiger_activity.date_start between ? AND ?) + OR (vtiger_activity.date_start < ? AND vtiger_activity.due_date > ?) + OR (vtiger_activity.due_date between ? AND ?))"; + + $q= "select vtiger_activity.*, vtiger_crmentity.*, case when (vtiger_users.user_name not like '') then vtiger_users.user_name else vtiger_groups.groupname end as user_name FROM vtiger_activity inner join vtiger_crmentity on vtiger_activity.activityid = vtiger_crmentity.crmid left join vtiger_recurringevents on vtiger_activity.activityid=vtiger_recurringevents.activityid left join vtiger_groups on vtiger_groups.groupid = vtiger_crmentity.smownerid LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid WHERE vtiger_crmentity.deleted = 0 and vtiger_activity.activitytype not in ('Emails','Task') $and "; + + // User Select Customization: Changes should made also in (calendayLaout getEventList) and one more BELOW + $query_filter_prefix = calendarview_getSelectedUserFilterQuerySuffix(); + $q .= $query_filter_prefix; + // END + $params = array($from_datetime->get_formatted_date(), $to_datetime->get_formatted_date(), $from_datetime->get_formatted_date(), $from_datetime->get_formatted_date(), $from_datetime->get_formatted_date(), $to_datetime->get_formatted_date()); + if($is_admin==false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $defaultOrgSharingPermission[16] == 3) + { + //Added for User Based Custom View for Calendar + $sec_parameter=getCalendarViewSecurityParameter(); + $q .= $sec_parameter; + } + + $q .= " AND vtiger_recurringevents.activityid is NULL "; + $q .= " group by vtiger_activity.activityid ORDER by vtiger_activity.date_start,vtiger_activity.time_start"; + + $r = $adb->pquery($q, $params); + $n = $adb->getRowCount($r); + $a = 0; + $list = Array(); + + while ( $a < $n ) + { + + $result = $adb->fetchByAssoc($r); + $start_timestamp = strtotime($result["date_start"]); + $end_timestamp = strtotime($result["due_date"]); + if($from_datetime->ts <= $start_timestamp) $from = $start_timestamp; + else $from = $from_datetime->ts; + if($to_datetime->ts <= $end_timestamp) $to = $to_datetime->ts; + else $to = $end_timestamp; + for($j = $from; $j <= $to; $j=$j+(60*60*24)) + { + + $obj = &new Appointment(); + $temp_start = date("Y-m-d",$j); + $result["date_start"]= $temp_start ; + list($obj->temphour,$obj->tempmin) = explode(":",$result["time_start"]); + if($start_timestamp != $end_timestamp && $view == 'day'){ + if($j == $start_timestamp){ + $result["duration_hours"] = 24 - $obj->temphour; + }elseif($j > $start_timestamp && $j < $end_timestamp){ + list($obj->temphour,$obj->tempmin)= $current_user->start_hour !=''?explode(":",$current_user->start_hour):explode(":","08:00"); + $result["duration_hours"] = 24 - $obj->temphour; + }elseif($j == $end_timestamp){ + list($obj->temphour,$obj->tempmin)= $current_user->start_hour !=''?explode(":",$current_user->start_hour):explode(":","08:00"); + list($ehr,$emin) = explode(":",$result["time_end"]); + $result["duration_hours"] = $ehr - $obj->temphour; + } + } + $obj->readResult($result, $view); + $list[] = $obj; + unset($obj); + + } + $a++; + + } + //Get Recurring events + $q = "SELECT vtiger_activity.*, vtiger_crmentity.*, case when (vtiger_users.user_name not like '') then vtiger_users.user_name else vtiger_groups.groupname end as user_name , vtiger_recurringevents.recurringid, vtiger_recurringevents.recurringdate as date_start ,vtiger_recurringevents.recurringtype,vtiger_groups.groupname from vtiger_activity inner join vtiger_crmentity on vtiger_activity.activityid = vtiger_crmentity.crmid inner join vtiger_recurringevents on vtiger_activity.activityid=vtiger_recurringevents.activityid left join vtiger_groups on vtiger_groups.groupid = vtiger_crmentity.smownerid LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid"; + $q .= getNonAdminAccessControlQuery('Calendar',$current_user); + $q.=" where vtiger_crmentity.deleted = 0 and vtiger_activity.activitytype not in ('Emails','Task') AND (recurringdate between ? and ?) "; + + // User Select Customization + $q .= $query_filter_prefix; + // END + + $params = array($from_datetime->get_formatted_date(), $to_datetime->get_formatted_date()); + + $q .= " ORDER by vtiger_recurringevents.recurringid"; + $r = $adb->pquery($q, $params); + $n = $adb->getRowCount($r); + $a = 0; + while ( $a < $n ) + { + $obj = &new Appointment(); + $result = $adb->fetchByAssoc($r); + list($obj->temphour,$obj->tempmin) = explode(":",$result["time_start"]); + $obj->readResult($result,$view); + $a++; + $list[] = $obj; + unset($obj); + } + + + usort($list,'compare'); + return $list; + } + + + /** To read and set the events value in Appointment Obj + * @param $act_array -- The vtiger_activity array :: Type Array + * @param $view -- The calendar view :: Type String + */ + function readResult($act_array, $view) + { + global $adb,$current_user,$app_strings; + $format_sthour=''; + $format_stmin=''; + $this->description = $act_array["description"]; + $this->eventstatus = getRoleBasesdPickList('eventstatus',$act_array["eventstatus"]); + $this->priority = getRoleBasesdPickList('taskpriority',$act_array["priority"]); + $this->subject = $act_array["subject"]; + $this->activity_type = $act_array["activitytype"]; + $this->duration_hour = $act_array["duration_hours"]; + $this->duration_minute = $act_array["duration_minutes"]; + $this->creatorid = $act_array["smcreatorid"]; + //$this->creator = getUserName($act_array["smcreatorid"]); + $this->assignedto = $act_array["user_name"]; + $this->owner = $act_array["user_name"]; + if(!is_admin($current_user)) + { + if($act_array["smownerid"]!=0 && $act_array["smownerid"] != $current_user->id && $act_array["visibility"] == "Public"){ + $que = "select * from vtiger_sharedcalendar where sharedid=? and userid=?"; + $row = $adb->pquery($que, array($current_user->id, $act_array["smownerid"])); + $no = $adb->getRowCount($row); + if($no > 0) + $this->shared = true; + } + } + $this->image_name = $act_array["activitytype"].".gif"; + if(!empty($act_array["recurringid"]) && !empty($act_array["recurringtype"])) + $this->recurring="Recurring.gif"; + + $this->record = $act_array["activityid"]; + list($styear,$stmonth,$stday) = explode("-",$act_array["date_start"]); + if($act_array["notime"] != 1){ + $st_hour = twoDigit($this->temphour); + list($sthour,$stmin) = split(":",$act_array["time_start"]); + }else{ + $st_hour = 'notime'; + $stmin = '00'; + $sthour= '00'; + } + list($eyear,$emonth,$eday) = explode("-",$act_array["due_date"]); + list($end_hour,$end_min) = split(":",$act_array["time_end"]); + + $start_date_arr = Array( + 'min' => $stmin, + 'hour' => $sthour, + 'day' => $stday, + 'month' => $stmonth, + 'year' => $styear + ); + $end_date_arr = Array( + 'min' => $end_min, + 'hour' => $end_hour, + 'day' => $eday, + 'month' => $emonth, + 'year' => $eyear + ); + $this->start_time = new vt_DateTime($start_date_arr,true); + $this->end_time = new vt_DateTime($end_date_arr,true); + if($view == 'day' || $view == 'week') + { + $this->formatted_datetime= $act_array["date_start"].":".$st_hour; + } + elseif($view == 'year') + { + list($year,$month,$date) = explode("-",$act_array["date_start"]); + $this->formatted_datetime = $month; + } + else + { + $this->formatted_datetime= $act_array["date_start"]; + } + return; + } + + +} + +/** To two array values + * @param $a -- The vtiger_activity array :: Type Array + * @param $b -- The vtiger_activity array :: Type Array + * @returns value 0 or 1 or -1 depends on comparision result + */ +function compare($a,$b) +{ + if ($a->start_time->ts == $b->start_time->ts) + { + return 0; + } + return ($a->start_time->ts < $b->start_time->ts) ? -1 : 1; +} +function getRoleBasesdPickList($fldname,$exist_val) +{ + global $adb,$app_strings,$current_user; + $is_Admin = $current_user->is_admin; + if($is_Admin == 'off' && $fldname != '') + { + $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_$fldname where $fldname=?"; + $res = $adb->pquery($sql,array(decode_html($exist_val))); + $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) + $pick_val = $exist_val; + else + $pick_val = $app_strings['LBL_NOT_ACCESSIBLE']; + + + }else + $pick_val = $exist_val; + + return $pick_val; + +} +?> diff --git a/oss/vtiger/trunk/modules/Calendar/Calendar.js b/oss/vtiger/trunk/modules/Calendar/Calendar.js new file mode 100644 index 00000000..e8d3fb8d --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/Calendar.js @@ -0,0 +1,123 @@ + +/********************************************************************************* + +** The contents of this file are subject to the vtiger CRM Public License Version 1.0 + * ("License"); You may not use this file except in compliance with the License + * The Original Code is: vtiger CRM Open Source + * The Initial Developer of the Original Code is vtiger. + * Portions created by vtiger are Copyright (C) vtiger. + * All Rights Reserved. + ********************************************************************************/ + +function set_values(form) { + + if (form.duedate_flag.checked) { + + form.duedate_flag.value='on'; + + form.duedate.value=""; + + form.duetime.value=""; + + form.duedate.readOnly=true; + + form.duetime.readOnly=true; + + document.images.jscal_trigger.width = 0; + + document.images.jscal_trigger.height = 0; + + } + + else { + + form.duedate_flag.value='off'; + + form.duedate.readOnly=false; + + form.duetime.readOnly=false; + + if (form.duetime.readonly) alert (alert_arr.READONLY); + + document.images.jscal_trigger.width = 16; + + document.images.jscal_trigger.height = 16; + + } + +} +function toggleTime() +{ + if(getObj("notime").checked) + { + getObj("notime").value = 'on'; + getObj("duration_hours").disabled = true; + getObj("duration_minutes").disabled = true; + } + else + { + getObj("notime").value = 'off'; + getObj("duration_minutes").disabled = false; + getObj("duration_hours").disabled = false; + } +} + +function toggleAssignType(currType) + +{ + + if (currType=="U") + + { + + getObj("assign_user").style.display="block" + + getObj("assign_team").style.display="none" + + } + + else + + { + + getObj("assign_user").style.display="none" + + getObj("assign_team").style.display="block" + + } + +} + +function showActivityView(selectactivity_view) +{ + //script to reload the page with the view type when the combo values are changed + View_name = selectactivity_view.options[selectactivity_view.options.selectedIndex].value; + document.frmOpenLstView.action = "index.php?module=Home&action=index&activity_view="+View_name; + document.frmOpenLstView.submit(); +} + +function exportCalendar(){ + if(document.getElementsByName('exportCalendar')[0].value == 'iCal'){ + var filename = $('ics_filename').value; + VtigerJS_DialogBox.block(); + + var url = "index.php?module=Calendar&action=iCalExport&filename="+filename; + location.href = url; + VtigerJS_DialogBox.unblock(); + ghide('CalExport') + } +} + +function importCalendar(){ + var file = document.getElementById('ics_file').value; + if (file != '') { + if (file.indexOf('.ics') != (file.length - 4)) { + alert(alert_arr.PLS_SELECT_VALID_FILE+".ics") + } + else { + document.ical_import.action.value='iCalImport'; + document.ical_import.module.value='Calendar'; + document.ical_import.submit(); + } + } +} diff --git a/oss/vtiger/trunk/modules/Calendar/Calendar.php b/oss/vtiger/trunk/modules/Calendar/Calendar.php new file mode 100644 index 00000000..50dfa3ce --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/Calendar.php @@ -0,0 +1,297 @@ +view = $view; + $this->date_time = new vt_DateTime($data,true); + $this->constructLayout(); + } + /** + * Function to get calendarview Label + * @param string $view - calendarview + * return string - calendarview Label + */ + function getCalendarView($view) + { + switch($view) + { + case 'day': + return "DAY"; + case 'week': + return "WEEK"; + case 'month': + return "MON"; + case 'year': + return "YEAR"; + } + } + + /** + * Function to set values for calendar object depends on calendar view + */ + function constructLayout() + { + global $current_user; + switch($this->view) + { + case 'day': + for($i=-1;$i<=23;$i++) + { + if($i == -1) + { + $layout = new Layout('hour',$this->date_time->getTodayDatetimebyIndex(0)); + $this->day_slice[$layout->start_time->get_formatted_date().':notime'] = $layout; + $this->slices['notime'] = $layout->start_time->get_formatted_date().":notime"; + } + else + { + $layout = new Layout('hour',$this->date_time->getTodayDatetimebyIndex($i)); + $this->day_slice[$layout->start_time->get_formatted_date().':'.$layout->start_time->z_hour] = $layout; + array_push($this->slices, $layout->start_time->get_formatted_date().":".$layout->start_time->z_hour); + } + } + break; + case 'week': + $weekview_days = 7; + for($i=0;$i<$weekview_days;$i++) + { + $layout = new Layout('day',$this->date_time->getThisweekDaysbyIndex($i)); + $this->week_array[$layout->start_time->get_formatted_date()] = $layout; + for($h=-1;$h<=23;$h++) + { + if($h == -1) + { + $hour_list = new Layout('hour',$this->date_time->getTodayDatetimebyIndex(0,$layout->start_time->day,$layout->start_time->month,$layout->start_time->year)); + $this->week_slice[$layout->start_time->get_formatted_date().':notime'] = $hour_list; + $this->week_hour_slices['notime'] = $layout->start_time->get_formatted_date().":notime"; + } + else + { + $hour_list = new Layout('hour',$this->date_time->getTodayDatetimebyIndex($h,$layout->start_time->day,$layout->start_time->month,$layout->start_time->year)); + $this->week_slice[$layout->start_time->get_formatted_date().':'.$hour_list->start_time->z_hour] = $hour_list; + array_push($this->week_hour_slices, $layout->start_time->get_formatted_date().":".$hour_list->start_time->z_hour); + } + } + array_push($this->slices, $layout->start_time->get_formatted_date()); + + } + break; + case 'month': + $arr = getCalendarDaysInMonth($this->date_time); + $this->month_array = $arr["month_array"]; + $this->slices = $arr["slices"]; + $this->date_time = $arr["date_time"]; + break; + case 'year': + $this->month_day_slices = Array(); + for($i=0;$i<12;$i++){ + $currMonth = $this->date_time->getThisyearMonthsbyIndex($i); + $layout = new Layout('month',$this->date_time->getThisyearMonthsbyIndex($i)); + $this->year_array[$layout->start_time->z_month] = $layout; + + $arr = getCalendarDaysInMonth($currMonth); + $slices = $arr["slices"]; + + $this->month_day_slices[$i] = $slices; + array_push($this->slices, $layout->start_time->z_month); + } + break; + } + } + + /** + * Function to get date info depends on calendarview + * @param string $type - string 'increment' or 'decrment' + */ + + function get_datechange_info($type) + { + if($type == 'next') + $mode = 'increment'; + if($type == 'prev') + $mode = 'decrment'; + switch($this->view) + { + case 'day': + $day = $this->date_time->get_changed_day($mode); + break; + case 'week': + $day = $this->date_time->get_first_day_of_changed_week($mode); + break; + case 'month': + $day = $this->date_time->get_first_day_of_changed_month($mode); + break; + case 'year': + $day = $this->date_time->get_first_day_of_changed_year($mode); + break; + default: + return "view is not supported"; + } + return $day->get_date_str(); + } + + /** + * Function to get activities + * @param array $current_user - user data + * @param string $free_busy - + */ + function add_Activities($current_user,$free_busy='') + { + if(isset($current_user->start_hour) && $current_user->start_hour !='') + { + list($sthour,$stmin)= explode(":",$current_user->start_hour); + $hr = $sthour+0; + $this->day_start_hour=$hr; + } + else + { + $this->day_start_hour=8; + } + if(isset($current_user->end_hour) && $current_user->end_hour !='') + { + list($endhour,$endmin)=explode(":",$current_user->end_hour); + $endhour = $endhour+0; + $this->day_end_hour=$endhour; + } + else + { + $this->day_end_hour=23; + } + if ( $this->view == 'week') + { + $start_datetime = $this->date_time->getThisweekDaysbyIndex(0); + $end_datetime = $this->date_time->getThisweekDaysbyIndex(6); + } elseif($this->view == 'month') { + $start_datetime = $this->date_time->getThismonthDaysbyIndex(0); + $end_datetime = $this->date_time->getThismonthDaysbyIndex($this->date_time->daysinmonth-1); + } elseif($this->view == 'year'){ + $start_datetime = $this->date_time->getThisyearMonthsbyIndex(0); + $end_datetime = $this->date_time->get_first_day_of_changed_year('increment'); + }else { + $start_datetime = $this->date_time; + $end_datetime = $this->date_time->getTodayDatetimebyIndex(23); + } + + $activities = Array(); + $activities = Appointment::readAppointment($current_user->id,$start_datetime,$end_datetime,$this->view); + if(!empty($activities)) + { + foreach($activities as $key=>$value) + { + if($this->view == 'day') + { + array_push($this->day_slice[$value->formatted_datetime]->activities, $value); + } + elseif($this->view == 'week') + { + array_push($this->week_slice[$value->formatted_datetime]->activities, $value); + } + elseif($this->view == 'month') + { + array_push($this->month_array[$value->formatted_datetime]->activities,$value); + } + elseif($this->view == 'year') + { + array_push($this->year_array[$value->formatted_datetime]->activities,$value); + } + else + die("view:".$this->view." is not defined"); + + } + } + + } +} + +class Layout +{ + var $view = 'day'; + var $start_time; + var $end_time; + var $activities = Array(); + + /** + * Constructor for Layout class + * @param string $view - calendarview + * @param string $time - time string + */ + + function Layout($view,$time) + { + $this->view = $view; + $this->start_time = $time; + if ( $view == 'month') + $this->end_time = $this->start_time->getMonthendtime(); + if ( $view == 'day') + $this->end_time = $this->start_time->getDayendtime(); + if ( $view == 'hour') + $this->end_time = $this->start_time->getHourendtime(); + } + + /** + * Function to get view + * return currentview + */ + + function getView() + { + return $this->view; + } +} + +/** + * this function returns the days in a month in an array format + * @param object $date_time - the date time object for the current month + * @return array $result - the array containing current months days information + */ +function getCalendarDaysInMonth($date_time){ + global $current_user; + $month_array = array(); + $slices = array(); + $monthview_days = $date_time->daysinmonth; + + $firstday_of_month = $date_time->getThisMonthsDayByIndex(0); + $fdom = $firstday_of_month; + + $num_of_prev_days = ($fdom->dayofweek+1)%7-1; + for($i=-$num_of_prev_days;$i<42;$i++){ + $pd = $date_time->getThisMonthsDayByIndex($i); + + $layout = new Layout('day', $pd); + $month_array[$layout->start_time->get_formatted_date()] = $layout; + array_push($slices, $layout->start_time->get_formatted_date()); + } + + $result = array("month_array"=>$month_array, "slices"=>$slices, "date_time"=>$date_time); + return $result; +} +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/CalendarAjax.php b/oss/vtiger/trunk/modules/Calendar/CalendarAjax.php new file mode 100644 index 00000000..ce66087f --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/CalendarAjax.php @@ -0,0 +1,13 @@ + diff --git a/oss/vtiger/trunk/modules/Calendar/CalendarCommon.php b/oss/vtiger/trunk/modules/Calendar/CalendarCommon.php new file mode 100644 index 00000000..1d84a78b --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/CalendarCommon.php @@ -0,0 +1,608 @@ +pquery($query, array($id)); + $rows = $adb->num_rows($result); + for($j=0;$j<$rows;$j++) + { + + $id = $adb->query_result($result,$j,'sharedid'); + $sharedname = $adb->query_result($result,$j,'user_name'); + $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=$adb->query_result($result,$i,'user_name'); + $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 = getUserName($user_id); + + if($from == "invite") + $msg = getTranslatedString($mod_strings['LBL_ACTIVITY_INVITATION']); + else + $msg = getTranslatedString($mod_strings['LBL_ACTIVITY_NOTIFICATION']); + + $current_username = getUserName($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']; + $list .= '
      '.$end_date_lable.' : '.$description['end_date_time']; + $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){ + + 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 = ($hr >= 12) ? "pm" : "am"; + if($hr == 0) $hr = 12; + $timeStr .= ($hr>12)?($hr-12):$hr; + $timeStr .= ":".twoDigit($min); + $timeStr .= $am; + } + return $timeStr; +} +//added to fix Ticket#3068 +function getEventNotification($mode,$subject,$desc) +{ + global $current_user,$adb; + require_once("modules/Emails/mail.php"); + $subject = $mode.' : '.$subject; + $crmentity = new CRMEntity(); + if(getUserName($desc['user_id'])) + { + $to_email = getUserEmailId('id',$desc['user_id']); + $description = getActivityDetails($desc,$desc['user_id']); + send_mail('Calendar',$to_email,$current_user->user_name,'',$subject,$description); + } + else + { + $groupid = $desc['user_id']; + require_once('include/utils/GetGroupUsers.php'); + $getGroupObj=new GetGroupUsers(); + $getGroupObj->getAllUsersInGroup($groupid); + $userIds=$getGroupObj->group_users; + if (count($userIds) > 0) { + $groupqry="select email1,id from vtiger_users where id in(".generateQuestionMarks($userIds).")"; + $groupqry_res=$adb->pquery($groupqry, array($userIds)); + $noOfRows = $adb->num_rows($groupqry_res); + for($z=0;$z < $noOfRows;$z++) + { + $emailadd = $adb->query_result($groupqry_res,$z,'email1'); + $curr_userid = $adb->query_result($groupqry_res,$z,'id'); + $description = getActivityDetails($desc,$curr_userid); + $mail_status = send_mail('Calendar',$emailadd,getUserName($curr_userid),'',$subject,$description); + + } + } + } +} + +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"); + + $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"); + + + $cont_qry = "select * from vtiger_cntactivityrel where activityid=?"; + $cont_res = $adb->pquery($cont_qry, array($return_id)); + $cont_id = $adb->query_result($cont_res,0,"contactid"); + $cont_name = ''; + if($cont_id != '') + { + $cont_name = getContactName($cont_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'] = $cont_name; + $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']; + $mail_data['st_date_time']=getDisplayDate($st_date)." ".$start_hour; + $mail_data['end_date_time']=getDisplayDate($end_date)." ".$end_hour; + $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 + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/CustomView.php b/oss/vtiger/trunk/modules/Calendar/CustomView.php new file mode 100644 index 00000000..93231ed6 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/CustomView.php @@ -0,0 +1,14 @@ + diff --git a/oss/vtiger/trunk/modules/Calendar/Date.php b/oss/vtiger/trunk/modules/Calendar/Date.php new file mode 100644 index 00000000..b89bd64f --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/Date.php @@ -0,0 +1,511 @@ +setDateTime(null); + } + else if ( isset( $timearr['ts'])) + { + $this->setDateTime($time['ts']); + } + else + { + if(isset($timearr['hour']) && $timearr['hour'] !== '') + { + $this->hour = $timearr['hour']; + } + if(isset($timearr['min']) && $timearr['min'] !== '') + { + $this->minute = $timearr['min']; + } + if(isset($timearr['sec']) && $timearr['sec'] !== '') + { + $this->second = $timearr['sec']; + } + if(isset($timearr['day']) && $timearr['day'] !== '') + { + $this->day = $timearr['day']; + } + if(isset($timearr['week']) && $timearr['week'] !== '') + { + $this->week = $timearr['week']; + } + if(isset($timearr['month']) && $timearr['month'] !== '') + { + $this->month = $timearr['month']; + } + if(isset($timearr['year']) && $timearr['year'] >= 1970) + { + $this->year = $timearr['year']; + } + else + { + return null; + } + } + if ($check) + { + $this->getDateTime(); + } + } + + /** + * function to get date and time using index + * @param integer $index - number between 0 to 23 + * @param string $day - date + * @param string $month - month + * @param string $year - year + * return vt_DateTime obj $datetimevalue + */ + function getTodayDatetimebyIndex($index,$day='', $month='', $year=''){ + if($day === '') + $day = $this->day; + if($month === '') + $month = $this->month; + if($year === '') + $year = $this->year; + $day_array = array(); + + if($index < 0 || $index > 23){ + die("hour is invalid"); + } + + $day_array['hour'] = $index; + $day_array['min'] = 0; + $day_array['day'] = $day; + $day_array['month'] = $month; + $day_array['year'] = $year; + $datetimevalue = new vt_DateTime($day_array,true); + return $datetimevalue; + } + + /** + * function to get days in week using index + * @param integer $index - number between 0 to 6 + * return vt_DateTime obj $datetimevalue + */ + function getThisweekDaysbyIndex($index){ + $week_array = array(); + if($index < 0 || $index > 6){ + die("day is invalid"); + } + $week_array['day'] = $this->day + ($index - $this->dayofweek); + $week_array['month'] = $this->month; + $week_array['year'] = $this->year; + $datetimevalue = new vt_DateTime($week_array,true); + return $datetimevalue; + } + + /** + * function to get days in month using index + * + * This function will be deprecated. + * The newer version is getThisMonthsDayByIndex() and should be used wherever possible + * + * @param integer $index - number between 0 to 42 + * @param string $day - date + * @param string $month - month + * @param string $year - year + * return vt_DateTime obj $datetimevalue + */ + + function getThismonthDaysbyIndex($index,$day='', $month='', $year='') + { + if($day == '') + $day = $index+1; + if($month == '') + $month = $this->month; + if($year == '') + $year = $this->year; + $month_array = array(); + $month_array['day'] = $day; + $month_array['month'] = $month; + $month_array['year'] = $year; + $datetimevalue = new vt_DateTime($month_array,true); + return $datetimevalue; + } + + /** + * function to get months in year using index + * @param integer $index - number between 0 to 11 + * return vt_DateTime obj $datetimevalue + */ + + function getThisyearMonthsbyIndex($index) + { + $year_array = array(); + $year_array['day'] = 1; + if($index < 0 || $index > 11) + { + die("month is invalid"); + } + $year_array['month'] = $index+1; + $year_array['year'] = $this->year; + $datetimevalue = new vt_DateTime($year_array,true); + return $datetimevalue; + } + + /** + * function to get hour end time + * return vt_DateTime obj $datetimevalue + */ + + function getHourendtime() + { + $date_array = array(); + $date_array['hour'] = $this->hour; + $date_array['min'] = 59; + $date_array['day'] = $this->day; + $date_array['sec'] = 59; + $date_array['month'] = $this->month; + $date_array['year'] = $this->year; + $datetimevalue = new vt_DateTime($date_array,true); + return $datetimevalue; + } + + /** + * function to get day end time + * return vt_DateTime obj $datetimevalue + */ + function getDayendtime() + { + $date_array = array(); + $date_array['hour'] = 23; + $date_array['min'] = 59; + $date_array['sec'] = 59; + $date_array['day'] = $this->day; + $date_array['month'] = $this->month; + $date_array['year'] = $this->year; + $datetimevalue = new vt_DateTime($date_array,true); + return $datetimevalue; + } + + /** + * function to get month end time + * return vt_DateTime obj $datetimevalue + */ + function getMonthendtime() + { + $date_array = array(); + $date_array['hour'] = 23; + $date_array['min'] = 59; + $date_array['sec'] = 59; + $date_array['day'] = $this->daysinmonth; + $date_array['month'] = $this->month; + $date_array['year'] = $this->year; + $datetimevalue = new vt_DateTime($date_array,true); + return $datetimevalue; + } + + /** + * function to get day of week + * return string $this->day - day (eg: Monday) + */ + function get_Date() + { + return $this->day; + } + + /** + * function to get month name in short + * return string $this->month_inshort - month name (eg: Jan) + */ + function getmonthName_inshort(){ + return $this->month_inshort; + } + /** + * function to get month name + * return string $this->month - month name + */ + function getMonth(){ + return $this->month; + } + /** + * function to get month name + * return string $this->month_inlong - month name + */ + function getmonthName(){ + return $this->month_inlong; + } + + /** + * function to get day of week + * return string $this->dayofweek_inlong - day of week + */ + function getdayofWeek(){ + return $this->dayofweek_inlong; + } + /** + * function to get day of week in short + * return string $this->dayofweek_inshort - day of week (eg: Mon) + */ + + function getdayofWeek_inshort(){ + return $this->dayofweek_inshort; + } + + /** + * function to set values for vt_DateTime object + * @param integer $ts - Time stamp + */ + function setDateTime($ts){ + global $mod_strings; + if (empty($ts)){ + $ts = time(); + } + + $this->ts = $ts; + $this->ts_def = $this->ts; + $date_string = date('i::G::H::j::d::t::w::z::L::W::n::m::Y::Z::T::s',$ts); + + list($this->minute,$this->hour,$this->z_hour,$this->day,$this->z_day,$this->daysinmonth,$this->dayofweek,$this->dayofyear,$is_leap,$this->week,$this->month,$this->z_month,$this->year,$this->offset,$this->tz,$this->second) = split('::',$date_string); + + $this->dayofweek_inshort =$mod_strings['cal_weekdays_short'][$this->dayofweek]; + $this->dayofweek_inlong=$mod_strings['cal_weekdays_long'][$this->dayofweek]; + $this->month_inshort=$mod_strings['cal_month_short'][$this->month]; + $this->month_inlong=$mod_strings['cal_month_long'][$this->month]; + + $this->daysinyear = 365; + + if ($is_leap == 1){ + $this->daysinyear += 1; + } + } + + /** + * function to get values from vt_DateTime object + */ + function getDateTime() + { + global $mod_strings; + $hour = 0; + $minute = 0; + $second = 0; + $day = 1; + $month = 1; + $year = 1970; + + if ( isset($this->second) && $this->second !== ''){ + $second = $this->second; + } + if ( isset($this->minute) && $this->minute !== ''){ + $minute = $this->minute; + } + if ( isset($this->hour) && $this->hour !== '') + { + $hour = $this->hour; + } + if ( isset($this->day) && $this->day !== ''){ + $day= $this->day; + } + if ( isset($this->month) && $this->month !== ''){ + $month = $this->month; + } + + if ( isset($this->year) && $this->year !== ''){ + $year = $this->year; + }else{ + die("year was not set"); + } + if(empty($hour) && $hour !== 0) $hour = 0; + $this->ts = mktime($hour,$minute,$second,$month,$day,$year); + $this->setDateTime($this->ts); + } + + /** + * function to get mysql formatted date + * return formatted date in string format + */ + function get_formatted_date(){ + return $this->year."-".$this->z_month."-".$this->z_day; + } + /** + * function to get mysql formatted time + * return formatted time in string format + */ + function get_formatted_time(){ + return $this->z_hour.":".$this->min; + } + + /** + * function to get date depends on mode value + * @param string $mode - 'increment' or 'decrement' + * return vt_DateTime obj + */ + function get_changed_day($mode){ + if($mode == 'increment') + $day = $this->day + 1; + else + $day = $this->day - 1; + $date_data = array('day'=>$day, + 'month'=>$this->month, + 'year'=>$this->year + ); + return new vt_DateTime($date_data,true); + } + + /** + * function to get changed week depends on mode value + * @param string $mode - 'increment' or 'decrement' + * return vt_DateTime obj + */ + function get_first_day_of_changed_week($mode){ + $first_day = $this->getThisweekDaysbyIndex(0); + if($mode == 'increment') + $day = $first_day->day + 7; + else + $day = $first_day->day - 7; + $date_data = array('day'=>$day, + 'month'=>$first_day->month, + 'year'=>$first_day->year + ); + return new vt_DateTime($date_data,true); + } + + /** + * function to get month depends on mode value + * @param string $mode - 'increment' or 'decrement' + * return vt_DateTime obj + */ + function get_first_day_of_changed_month($mode){ + $tmpDate['day'] = $this->day; + $tmpDate['month'] = $this->month; + $tmpDate['year'] = $this->year; + + if(is_array($arr) && !empty($arr)){ + $tmpDate['year'] = $arr[0]; + $tmpDate['month'] = $arr[1]; + $tmpDate['day'] = $arr[2]; + } + + if($mode == 'increment'){ + $month = $tmpDate['month'] + 1; + $year = $tmpDate['year'] ; + }else{ + if($tmpDate['month'] == 1){ + $month = 12; + $year = $tmpDate['year'] - 1; + }else{ + $month = $tmpDate['month'] - 1; + $year = $tmpDate['year'] ; + } + } + $date_data = array( + 'day'=>1, + 'month'=>$month, + 'year'=>$year + ); + + return new vt_DateTime($date_data,true); + } + + /** + * function to get year depends on mode value + * @param string $mode - 'increment' or 'decrement' + * return vt_DateTime obj + */ + function get_first_day_of_changed_year($mode){ + if($mode == 'increment'){ + $year = $this->year + 1; + }else{ + $year = $this->year - 1; + } + $date_data = array('day'=>1, + 'month'=>1, + 'year'=>$year + ); + return new vt_DateTime($date_data,true); + } + + /** + * function to get date string + * return date string + */ + function get_date_str(){ + $array = Array(); + if ( isset( $this->hour) && $this->hour != '') + { + array_push( $array, "hour=".$this->hour); + } + if ( isset( $this->day) && $this->day != '') + { + array_push( $array, "day=".$this->day); + } + if ( isset( $this->month) && $this->month) + { + array_push( $array, "month=".$this->month); + } + if ( isset( $this->year) && $this->year != '') + { + array_push( $array, "year=".$this->year); + } + return ("&".implode('&',$array)); + } + + /** + * function to get days in month using index + * + * This is the newer version of the function getThismonthDaysbyIndex(). + * This should be used whereever possible + * + * @param integer $index - number between 0 to 42 + * @param string $day - date + * @param string $month - month + * @param string $year - year + * return vt_DateTime obj $datetimevalue + */ + + function getThisMonthsDayByIndex($index){ + $day = $index; + $month = $this->month; + $year = $this->year; + $month_array = array(); + $month_array['day'] = $day; + $month_array['month'] = $month; + $month_array['year'] = $year; + $datetimevalue = new vt_DateTime($month_array,true); + return $datetimevalue; + } +} +?> diff --git a/oss/vtiger/trunk/modules/Calendar/Delete.php b/oss/vtiger/trunk/modules/Calendar/Delete.php new file mode 100644 index 00000000..e1017d8d --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/Delete.php @@ -0,0 +1,36 @@ + \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/DetailView.php b/oss/vtiger/trunk/modules/Calendar/DetailView.php new file mode 100644 index 00000000..0c3de6a6 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/DetailView.php @@ -0,0 +1,359 @@ +'. $mod_strings{"LBL_NOTIFICATION_ERROR"}.'
'; +} +session_unregister('mail_send_error'); + +$focus = CRMEntity::getInstance($currentModule); +$smarty = new vtigerCRM_Smarty(); +$activity_mode = vtlib_purify($_REQUEST['activity_mode']); +//If activity_mode == null + +if($activity_mode =='' || strlen($activity_mode) < 1) +{ + $query = "select activitytype from vtiger_activity where activityid=?"; + $result = $adb->pquery($query, array($_REQUEST['record'])); + $actType = $adb->query_result($result,0,'activitytype'); + if( $actType == 'Task') + { + $activity_mode = $actType; + } + elseif($actType != 'Emails') + { + $activity_mode = 'Events'; + } +} + +if($activity_mode == 'Task') +{ + $tab_type = 'Calendar'; + $smarty->assign("SINGLE_MOD",$mod_strings['LBL_TODO']); +} +elseif($activity_mode == 'Events') +{ + $tab_type = 'Events'; + $smarty->assign("SINGLE_MOD",$mod_strings['LBL_EVENT']); +} +$tab_id=getTabid($tab_type); + + +if(isset($_REQUEST['record']) && isset($_REQUEST['record'])) { + $focus->retrieve_entity_info($_REQUEST['record'],$tab_type); + $focus->id = $_REQUEST['record']; + $focus->name=$focus->column_fields['subject']; +} + +if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') { + $focus->id = ""; +} + +//needed when creating a new task with default values passed in +if (isset($_REQUEST['contactname']) && is_null($focus->contactname)) { + $focus->contactname = $_REQUEST['contactname']; +} +if (isset($_REQUEST['contact_id']) && is_null($focus->contact_id)) { + $focus->contact_id = $_REQUEST['contact_id']; +} +if (isset($_REQUEST['opportunity_name']) && is_null($focus->parent_name)) { + $focus->parent_name = $_REQUEST['opportunity_name']; +} +if (isset($_REQUEST['opportunity_id']) && is_null($focus->parent_id)) { + $focus->parent_id = $_REQUEST['opportunity_id']; +} +if (isset($_REQUEST['accountname']) && is_null($focus->parent_name)) { + $focus->parent_name = $_REQUEST['accountname']; +} +if (isset($_REQUEST['accountid']) && is_null($focus->parent_id)) { + $focus->parent_id = $_REQUEST['accountid']; +} + +$act_data = getBlocks($tab_type,"detail_view",'',$focus->column_fields); + +foreach($act_data as $block=>$entry) +{ + foreach($entry as $key=>$value) + { + foreach($value as $label=>$field) + { + $fldlabel[$field['fldname']] = $label; + if($field['ui'] == 15 || $field['ui'] == 16) + { + foreach($field['options'] as $index=>$arr_val) + { + if($arr_val[2] == "selected") + $finaldata[$field['fldname']] = $arr_val[0]; + } + } + else + { + $fldvalue = $field['value']; + if($field['fldname'] == 'description') { $fldvalue = nl2br($fldvalue); } + $finaldata[$field['fldname']] = $fldvalue; + } + + $finaldata[$field['fldname'].'link'] = $field['link']; + } + } +} + +//Start +//To set user selected hour format +if($current_user->hour_format == '') + $format = 'am/pm'; +else + $format = $current_user->hour_format; +list($stdate,$sttime) = split(' ',$finaldata['date_start']); +list($enddate,$endtime) = split(' ',$finaldata['due_date']); +$time_arr = getaddEventPopupTime($sttime,$endtime,$format); +$data['starthr'] = $time_arr['starthour']; +$data['startmin'] = $time_arr['startmin']; +$data['startfmt'] = $time_arr['startfmt']; +$data['endhr'] = $time_arr['endhour']; +$data['endmin'] = $time_arr['endmin']; +$data['endfmt'] = $time_arr['endfmt']; +$data['record'] = $focus->id; +if(isset($finaldata['sendnotification']) && $finaldata['sendnotification'] == 'yes') + $data['sendnotification'] = $mod_strings['LBL_YES']; +else + $data['sendnotification'] = $mod_strings['LBL_NO']; +$data['subject'] = $finaldata['subject']; +$data['date_start'] = $stdate; +$data['due_date'] = $enddate; +$data['assigned_user_id'] = $finaldata['assigned_user_id']; +if($mod_strings[$finaldata['taskpriority']] != '') + $data['taskpriority'] = $mod_strings[$finaldata['taskpriority']]; +else + $data['taskpriority'] = $finaldata['taskpriority']; +$data['modifiedtime'] = $finaldata['modifiedtime']; +$data['createdtime'] = $finaldata['createdtime']; +$data['parent_name'] = $finaldata['parent_id']; +$data['description'] = $finaldata['description']; +if($activity_mode == 'Task') +{ + if($mod_strings[$finaldata['taskstatus']] != '') + $data['taskstatus'] = $mod_strings[$finaldata['taskstatus']]; + else + $data['taskstatus'] = $finaldata['taskstatus']; + $data['activitytype'] = $activity_mode; + $data['contact_id'] = $finaldata['contact_id']; + $data['contact_idlink'] = $finaldata['contact_idlink']; +} +elseif($activity_mode == 'Events') +{ + $data['visibility'] = $finaldata['visibility']; + if($mod_strings[$finaldata['eventstatus']] != '') + $data['eventstatus'] = $mod_strings[$finaldata['eventstatus']]; + else + $data['eventstatus'] = $finaldata['eventstatus']; + $data['activitytype'] = $finaldata['activitytype']; + $data['location'] = $finaldata['location']; + //Calculating reminder time + $rem_days = 0; + $rem_hrs = 0; + $rem_min = 0; + if(!empty($focus->column_fields['reminder_time'])) + { + $data['set_reminder'] = $mod_strings['LBL_YES']; + $data['reminder_str'] = $finaldata['reminder_time']; + } + else + $data['set_reminder'] = $mod_strings['LBL_NO']; + //To set recurring details + $query = 'select vtiger_recurringevents.recurringfreq,vtiger_recurringevents.recurringinfo from vtiger_recurringevents where vtiger_recurringevents.activityid = ?'; + $res = $adb->pquery($query, array($focus->id)); + $rows = $adb->num_rows($res); + if($rows != 0) + { + $data['recurringcheck'] = $mod_strings['LBL_YES']; + $data['repeat_frequency'] = $adb->query_result($res,0,'recurringfreq'); + $recurringinfo = explode("::",$adb->query_result($res,0,'recurringinfo')); + $data['recurringtype'] = $recurringinfo[0]; + if($recurringinfo[0] == 'Weekly') + { + $weekrpt_str = ''; + if(count($recurringinfo) > 1) + { + $weekrpt_str .= 'on '; + for($i=1;$ipquery($sql, array($focus->id)); + $num_rows=$adb->num_rows($result); + $invited_users=Array(); + for($i=0;$i<$num_rows;$i++) + { + $userid=$adb->query_result($result,$i,'inviteeid'); + $username=$adb->query_result($result,$i,'user_name'); + $invited_users[$userid]=$username; + } + $smarty->assign("INVITEDUSERS",$invited_users); + $related_array = getRelatedListsInformation("Calendar", $focus); + + $smarty->assign("CONTACTS",$related_array['Contacts']['entries']); + + $is_fname_permitted = getFieldVisibilityPermission("Contacts", $current_user->id, 'firstname'); + $smarty->assign("IS_PERMITTED_CNT_FNAME",$is_fname_permitted); + + +} + +global $theme; +$theme_path="themes/".$theme."/"; +$image_path=$theme_path."images/"; + +$log->info("Calendar-Activities detail view"); +$category = getParentTab(); +$smarty->assign("CATEGORY",$category); + +$smarty->assign("MOD", $mod_strings); +$smarty->assign("APP", $app_strings); +$smarty->assign("ACTIVITY_MODE", $activity_mode); + +if (isset($focus->name)) +$smarty->assign("NAME", $focus->name); +else +$smarty->assign("NAME", ""); +$smarty->assign("UPDATEINFO",updateInfo($focus->id)); +if (isset($_REQUEST['return_module'])) +$smarty->assign("RETURN_MODULE", vtlib_purify($_REQUEST['return_module'])); +if (isset($_REQUEST['return_action'])) +$smarty->assign("RETURN_ACTION", vtlib_purify($_REQUEST['return_action'])); +if (isset($_REQUEST['return_id'])) +$smarty->assign("RETURN_ID", vtlib_purify($_REQUEST['return_id'])); +$smarty->assign("THEME", $theme); +$smarty->assign("IMAGE_PATH", $image_path); +$smarty->assign("PRINT_URL", "phprint.php?jt=".session_id().$GLOBALS['request_string'].'&activity_mode='.$activity_mode); +$smarty->assign("ID", $focus->id); +$smarty->assign("NAME", $focus->name); +$smarty->assign("BLOCKS", $act_data); +$smarty->assign("LABEL", $fldlabel); +$smarty->assign("VIEWTYPE", vtlib_purify($_REQUEST['viewtype'])); +$smarty->assign("CUSTOMFIELD", $cust_fld); +$smarty->assign("ACTIVITYDATA", $data); +$smarty->assign("ID", vtlib_purify($_REQUEST['record'])); + +//get Description Information +if(isPermitted("Calendar","EditView",$_REQUEST['record']) == 'yes') + $smarty->assign("EDIT_DUPLICATE","permitted"); + +if(isPermitted("Calendar","Delete",$_REQUEST['record']) == 'yes') + $smarty->assign("DELETE","permitted"); + +$check_button = Button_Check($module); +$smarty->assign("CHECK", $check_button); + + $tabid = getTabid($tab_type); + $validationData = getDBValidationData($focus->tab_name,$tabid); + $data2 = split_validationdataArray($validationData); + + $smarty->assign("VALIDATION_DATA_FIELDNAME",$data2['fieldname']); + $smarty->assign("VALIDATION_DATA_FIELDDATATYPE",$data2['datatype']); + $smarty->assign("VALIDATION_DATA_FIELDLABEL",$data2['fieldlabel']); + +$smarty->assign("MODULE",$currentModule); +$smarty->assign("EDIT_PERMISSION",isPermitted($currentModule,'EditView',$_REQUEST['record'])); + +if(PerformancePrefs::getBoolean('DETAILVIEW_RECORD_NAVIGATION', true) && isset($_SESSION[$currentModule.'_listquery'])){ + $recordNavigationInfo = ListViewSession::getListViewNavigation($focus->id); + VT_detailViewNavigation($smarty,$recordNavigationInfo,$focus->id); +} + +// Gather the custom link information to display +include_once('vtlib/Vtiger/Link.php'); +$customlink_params = Array('MODULE'=>$currentModule, 'RECORD'=>$focus->id, 'ACTION'=>vtlib_purify($_REQUEST['action'])); +$smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('DETAILVIEWBASIC','DETAILVIEW','DETAILVIEWWIDGET'), $customlink_params)); +// END + +$custom_fields_data = getCalendarCustomFields($tabid,'detail_view',$focus->column_fields); +$smarty->assign("CUSTOM_FIELDS_DATA", $custom_fields_data); + +$smarty->display("ActivityDetailView.tpl"); + +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/EditView.php b/oss/vtiger/trunk/modules/Calendar/EditView.php new file mode 100644 index 00000000..4328a094 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/EditView.php @@ -0,0 +1,297 @@ +assign("SEARCH", $searchurl); +//4600 ends + +$activity_mode = vtlib_purify($_REQUEST['activity_mode']); +if($activity_mode == 'Task') +{ + $tab_type = 'Calendar'; + $taskcheck = true; + $smarty->assign("SINGLE_MOD",$mod_strings['LBL_TODO']); +} +elseif($activity_mode == 'Events') +{ + $tab_type = 'Events'; + $taskcheck = false; + $smarty->assign("SINGLE_MOD",$mod_strings['LBL_EVENT']); +} + +if(isset($_REQUEST['record']) && $_REQUEST['record']!='') { + $focus->id = $_REQUEST['record']; + $focus->mode = 'edit'; + $focus->retrieve_entity_info($_REQUEST['record'],$tab_type); + $focus->name=$focus->column_fields['subject']; + $sql = 'select vtiger_users.user_name,vtiger_invitees.* from vtiger_invitees left join vtiger_users on vtiger_invitees.inviteeid=vtiger_users.id where activityid=?'; + $result = $adb->pquery($sql, array($focus->id)); + $num_rows=$adb->num_rows($result); + $invited_users=Array(); + for($i=0;$i<$num_rows;$i++) + { + $userid=$adb->query_result($result,$i,'inviteeid'); + $username=$adb->query_result($result,$i,'user_name'); + $invited_users[$userid]=$username; + } + $smarty->assign("INVITEDUSERS",$invited_users); + $smarty->assign("UPDATEINFO",updateInfo($focus->id)); + $related_array = getRelatedListsInformation("Calendar", $focus); + $cntlist = $related_array['Contacts']['entries']; + $is_fname_permitted = getFieldVisibilityPermission("Contacts", $current_user->id, 'firstname'); + $cnt_idlist = ''; + $cnt_namelist = ''; + if($cntlist != '') + { + $i = 0; + foreach($cntlist as $key=>$cntvalue) + { + if($i != 0) + { + $cnt_idlist .= ';'; + $cnt_namelist .= "\n"; + } + $cnt_idlist .= $key; + $contName = preg_replace("/(]*>)(.*)(<\/a>)/i", "\\2", $cntvalue[0]); + if ($is_fname_permitted == '0') $contName .= ' '.preg_replace("/(]*>)(.*)(<\/a>)/i", "\\2", $cntvalue[1]); + $cnt_namelist .= ''; + $i++; + } + } + $smarty->assign("CONTACTSID",$cnt_idlist); + $smarty->assign("CONTACTSNAME",$cnt_namelist); + $query = 'select vtiger_recurringevents.recurringfreq,vtiger_recurringevents.recurringinfo from vtiger_recurringevents where vtiger_recurringevents.activityid = ?'; + $res = $adb->pquery($query, array($focus->id)); + $rows = $adb->num_rows($res); + if($rows != 0) + { + $value['recurringcheck'] = 'Yes'; + $value['repeat_frequency'] = $adb->query_result($res,0,'recurringfreq'); + $recurringinfo = explode("::",$adb->query_result($res,0,'recurringinfo')); + $value['eventrecurringtype'] = $recurringinfo[0]; + if($recurringinfo[0] == 'Weekly') + { + for($i=0;$i<6;$i++) + { + $label = 'week'.$recurringinfo[$i+1]; + $value[$label] = 'checked'; + } + } + elseif($recurringinfo[0] == 'Monthly') + { + $value['repeatMonth'] = $recurringinfo[1]; + if($recurringinfo[1] == 'date') + { + $value['repeatMonth_date'] = $recurringinfo[2]; + } + else + { + $value['repeatMonth_daytype'] = $recurringinfo[2]; + $value['repeatMonth_day'] = $recurringinfo[3]; + } + } + } + else + { + $value['recurringcheck'] = 'No'; + } + +}else +{ + if(isset($_REQUEST['contact_id']) && $_REQUEST['contact_id']!=''){ + $smarty->assign("CONTACTSID",$_REQUEST['contact_id']); + $contact_name = ""; + $smarty->assign("CONTACTSNAME",$contact_name); + $account_id = $_REQUEST['account_id']; + $account_name = getAccountName($account_id); + } +} +if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') { + $focus->id = ""; + $focus->mode = ''; +} +if(empty($_REQUEST['record']) && $focus->mode != 'edit'){ + setObjectValuesFromRequest($focus); +} +$userDetails=getOtherUserName($current_user->id); +$to_email = getUserEmailId('id',$current_user->id); +$smarty->assign("CURRENTUSERID",$current_user->id); + +$disp_view = getView($focus->mode); +if($disp_view == 'edit_view') +{ + $act_data = getBlocks($tab_type,$disp_view,$mode,$focus->column_fields); +} +else +{ + $act_data = getBlocks($tab_type,$disp_view,$mode,$focus->column_fields,'BAS'); +} +$smarty->assign("BLOCKS",$act_data); +foreach($act_data as $header=>$blockitem) +{ + foreach($blockitem as $row=>$data) + { + foreach($data as $key=>$maindata) + { + $uitype[$maindata[2][0]] = $maindata[0][0]; + $fldlabel[$maindata[2][0]] = $maindata[1][0]; + $fldlabel_sel[$maindata[2][0]] = $maindata[1][1]; + $fldlabel_combo[$maindata[2][0]] = $maindata[1][2]; + $value[$maindata[2][0]] = $maindata[3][0]; + $secondvalue[$maindata[2][0]] = $maindata[3][1]; + $thirdvalue[$maindata[2][0]] = $maindata[3][2]; + } + } +} +// jread.topik. patch account_id for create contact +if (strlen($account_name) > 0) +{ + $fldlabel_sel['parent_id'][1]='selected'; + $secondvalue['parent_id'] = $account_id; + $value['parent_id'] = $account_name; +} + +$format = ($current_user->hour_format == '')?'am/pm':$current_user->hour_format; +$stdate = key($value['date_start']); +$enddate = key($value['due_date']); +$sttime = $value['date_start'][$stdate]; +$endtime = $value['due_date'][$enddate]; +$time_arr = getaddEventPopupTime($sttime,$endtime,$format); +$value['starthr'] = $time_arr['starthour']; +$value['startmin'] = $time_arr['startmin']; +$value['startfmt'] = $time_arr['startfmt']; +$value['endhr'] = $time_arr['endhour']; +$value['endmin'] = $time_arr['endmin']; +$value['endfmt'] = $time_arr['endfmt']; +$smarty->assign("STARTHOUR",getTimeCombo($format,'start',$time_arr['starthour'],$time_arr['startmin'],$time_arr['startfmt'],$taskcheck)); +$smarty->assign("ENDHOUR",getTimeCombo($format,'end',$time_arr['endhour'],$time_arr['endmin'],$time_arr['endfmt'])); +$smarty->assign("FOLLOWUP",getTimeCombo($format,'followup_start',$time_arr['endhour'],$time_arr['endmin'],$time_arr['endfmt'])); +$smarty->assign("ACTIVITYDATA",$value); +$smarty->assign("LABEL",$fldlabel); +$smarty->assign("secondvalue",$secondvalue); +$smarty->assign("thirdvalue",$thirdvalue); +$smarty->assign("fldlabel_combo",$fldlabel_combo); +$smarty->assign("fldlabel_sel",$fldlabel_sel); +$smarty->assign("OP_MODE",$disp_view); +$smarty->assign("ACTIVITY_MODE",$activity_mode); +$smarty->assign("HOURFORMAT",$format); +$smarty->assign("USERSLIST",$userDetails); +$smarty->assign("USEREMAILID",$to_email); +$smarty->assign("MODULE",$currentModule); +$smarty->assign("DATEFORMAT",parse_calendardate($app_strings['NTC_DATE_FORMAT'])); + +global $theme; +$theme_path="themes/".$theme."/"; +$image_path=$theme_path."images/"; + +$log->info("Activity edit view"); + +$smarty->assign("MOD", $mod_strings); +$smarty->assign("APP", $app_strings); + +if (isset($focus->name)) +$smarty->assign("NAME", $focus->name); +else +$smarty->assign("NAME", ""); + +if($focus->mode == 'edit') +{ + $smarty->assign("MODE", $focus->mode); +} + +$category = getParentTab(); +$smarty->assign("CATEGORY",$category); + +// Unimplemented until jscalendar language vtiger_files are fixed +$smarty->assign("CALENDAR_LANG", $app_strings['LBL_JSCALENDAR_LANG']); +$smarty->assign("CALENDAR_DATEFORMAT", parse_calendardate($app_strings['NTC_DATE_FORMAT'])); + +if (isset($_REQUEST['return_module'])) + $smarty->assign("RETURN_MODULE", vtlib_purify($_REQUEST['return_module'])); +if (isset($_REQUEST['return_action'])) + $smarty->assign("RETURN_ACTION",vtlib_purify( $_REQUEST['return_action'])); +if (isset($_REQUEST['return_id'])) + $smarty->assign("RETURN_ID", vtlib_purify($_REQUEST['return_id'])); +if (isset($_REQUEST['ticket_id'])) + $smarty->assign("TICKETID", $_REQUEST['ticket_id']); +if (isset($_REQUEST['product_id'])) + $smarty->assign("PRODUCTID", $_REQUEST['product_id']); +if (isset($_REQUEST['return_viewname'])) + $smarty->assign("RETURN_VIEWNAME", vtlib_purify($_REQUEST['return_viewname'])); +if(isset($_REQUEST['view']) && $_REQUEST['view']!='') + $smarty->assign("view",vtlib_purify($_REQUEST['view'])); +if(isset($_REQUEST['hour']) && $_REQUEST['hour']!='') + $smarty->assign("hour",vtlib_purify($_REQUEST['hour'])); +if(isset($_REQUEST['day']) && $_REQUEST['day']!='') + $smarty->assign("day",vtlib_purify($_REQUEST['day'])); +if(isset($_REQUEST['month']) && $_REQUEST['month']!='') + $smarty->assign("month",vtlib_purify($_REQUEST['month'])); +if(isset($_REQUEST['year']) && $_REQUEST['year']!='') + $smarty->assign("year",vtlib_purify($_REQUEST['year'])); +if(isset($_REQUEST['viewOption']) && $_REQUEST['viewOption']!='') + $smarty->assign("viewOption",vtlib_purify($_REQUEST['viewOption'])); +if(isset($_REQUEST['subtab']) && $_REQUEST['subtab']!='') + $smarty->assign("subtab",vtlib_purify($_REQUEST['subtab'])); +if(isset($_REQUEST['maintab']) && $_REQUEST['maintab']!='') + $smarty->assign("maintab",vtlib_purify($_REQUEST['maintab'])); + + +$smarty->assign("THEME", $theme); +$smarty->assign("IMAGE_PATH", $image_path); +$smarty->assign("PRINT_URL", "phprint.php?jt=".session_id().$GLOBALS['request_string']); +$smarty->assign("ID", $focus->id); + + $tabid = getTabid($tab_type); + $validationData = getDBValidationData($focus->tab_name,$tabid); + $data = split_validationdataArray($validationData); + +$check_button = Button_Check($module); +$smarty->assign("CHECK", $check_button); +$smarty->assign("DUPLICATE",vtlib_purify($_REQUEST['isDuplicate'])); + +if ($activity_mode == 'Task') { + $custom_fields_data = getCalendarCustomFields(getTabid('Calendar'),'edit',$focus->column_fields); +} else { + $custom_fields_data = getCalendarCustomFields(getTabid('Events'),'edit',$focus->column_fields); +} +$smarty->assign("CUSTOM_FIELDS_DATA", $custom_fields_data); + +$smarty->assign("REPEAT_LIMIT_DATEFORMAT", parse_calendardate($app_strings['NTC_DATE_FORMAT'])); + +$smarty->display("ActivityEditView.tpl"); + +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/ListView.php b/oss/vtiger/trunk/modules/Calendar/ListView.php new file mode 100644 index 00000000..7bb2422c --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/ListView.php @@ -0,0 +1,282 @@ +initSortbyField('Calendar'); +// END +$smarty = new vtigerCRM_Smarty; +$other_text = Array(); + +if(!$_SESSION['lvs'][$currentModule]) +{ + unset($_SESSION['lvs']); + $modObj = new ListViewSession(); + $modObj->sorder = $sorder; + $modObj->sortby = $order_by; + $_SESSION['lvs'][$currentModule] = get_object_vars($modObj); +} + +if($_REQUEST['errormsg'] != '') +{ + $errormsg = vtlib_purify($_REQUEST['errormsg']); + $smarty->assign("ERROR",$mod_strings["SHARED_EVENT_DEL_MSG"]); +}else +{ + $smarty->assign("ERROR",""); +} +//<<<<<<< sort ordering >>>>>>>>>>>>> +$sorder = $focus->getSortOrder(); +$order_by = $focus->getOrderBy(); + +$_SESSION['ACTIVITIES_ORDER_BY'] = $order_by; +$_SESSION['ACTIVITIES_SORT_ORDER'] = $sorder; +//<<<<<<< sort ordering >>>>>>>>>>>>> + + +//<<<>>>>>> +$oCustomView = new CustomView($currentModule); +$viewid = $oCustomView->getViewId($currentModule); +$customviewcombo_html = $oCustomView->getCustomViewCombo($viewid); +$viewnamedesc = $oCustomView->getCustomViewByCvid($viewid); + +//Added to handle approving or denying status-public by the admin in CustomView +$statusdetails = $oCustomView->isPermittedChangeStatus($viewnamedesc['status']); +$smarty->assign("CUSTOMVIEW_PERMISSION",$statusdetails); + +//To check if a user is able to edit/delete a customview +$edit_permit = $oCustomView->isPermittedCustomView($viewid,'EditView',$currentModule); +$delete_permit = $oCustomView->isPermittedCustomView($viewid,'Delete',$currentModule); +$smarty->assign("CV_EDIT_PERMIT",$edit_permit); +$smarty->assign("CV_DELETE_PERMIT",$delete_permit); + +//<<<<>>>> +if($viewid == 0 ) +{ + echo "
"; + echo "
+ + + + + + + + + +
'> + $app_strings[LBL_PERMISSION]
+ $app_strings[LBL_GO_BACK]
+
+
"; + echo "
"; + exit; +} + +$changeOwner = getAssignedTo(16); +$userList = $changeOwner[0]; +$groupList = $changeOwner[1]; + +$smarty->assign("CHANGE_USER",$userList); +$smarty->assign("CHANGE_GROUP",$groupList); +$smarty->assign("CHANGE_OWNER",getUserslist()); +$smarty->assign("CHANGE_GROUP_OWNER",getGroupslist()); +$where = ""; + +$url_string = ''; // assigning http url string + +if(isset($_REQUEST['query']) && $_REQUEST['query'] == 'true') +{ + + list($where, $ustring) = split("#@@#",getWhereCondition($currentModule)); + // we have a query + $url_string .="&query=true".$ustring; + $log->info("Here is the where clause for the list view: $where"); + $smarty->assign("SEARCH_URL",$url_string); +} + + +if($viewnamedesc['viewname'] == 'All') +{ + $smarty->assign("ALL", 'All'); +} + +if(isPermitted("Calendar","Delete",$_REQUEST['record']) == 'yes') +{ + $other_text['del'] = $app_strings[LBL_MASS_DELETE]; +} +if(isPermitted('Calendar','EditView','') == 'yes') +{ + $other_text['c_owner'] = $app_strings[LBL_CHANGE_OWNER]; +} +global $task_title; +$title_display = $current_module_strings['LBL_LIST_FORM_TITLE']; +if ($task_title) $title_display= $task_title; + +//Retreive the list from Database +//<<<<<<<<>>>>>>>> +if($viewid != "0") +{ + $listquery = getListQuery("Calendar"); + $list_query = $oCustomView->getModifiedCvListQuery($viewid,$listquery,"Calendar"); +}else +{ + $list_query = getListQuery("Calendar"); +} +//<<<<<<<>>>>>>>> + +if(isset($where) && $where != '') +{ + if(isset($_REQUEST['from_homepagedb']) && $_REQUEST['from_homepagedb'] == 'true') + $list_query .= " and ((vtiger_activity.status!='Completed' and vtiger_activity.status!='Deferred') or vtiger_activity.status is null) and ((vtiger_activity.eventstatus!='Held' and vtiger_activity.eventstatus!='Not Held') or vtiger_activity.eventstatus is null) AND ".$where; + else + $list_query .= " AND " .$where; +} +if (isset($_REQUEST['from_homepage'])) { + $today = date("Y-m-d", time()); + if ($_REQUEST['from_homepage'] == 'upcoming_activities') + $list_query .= " AND (vtiger_activity.status is NULL OR vtiger_activity.status not in ('Completed','Deferred')) and (vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus not in ('Held','Not Held')) AND (date_start >= '$today' OR vtiger_recurringevents.recurringdate >= '$today')"; + elseif ($_REQUEST['from_homepage'] == 'pending_activities') + $list_query .= " AND (vtiger_activity.status is NULL OR vtiger_activity.status not in ('Completed','Deferred')) and (vtiger_activity.eventstatus is NULL OR vtiger_activity.eventstatus not in ('Held','Not Held')) AND (due_date <= '$today' OR vtiger_recurringevents.recurringdate <= '$today')"; +} + +if(isset($order_by) && $order_by != '') { + if($order_by == 'smownerid') { + $list_query .= ' ORDER BY user_name '.$sorder; + } else { + $tablename = getTableNameForField('Calendar',$order_by); + $tablename = (($tablename != '')?($tablename."."):''); + if($order_by == 'lastname') + $list_query .= ' ORDER BY vtiger_contactdetails.lastname '.$sorder; + else + $list_query .= ' ORDER BY '.$tablename.$order_by.' '.$sorder; + } +} + +//Constructing the list view +$smarty->assign("CUSTOMVIEW_OPTION",$customviewcombo_html); +$smarty->assign("VIEWID", $viewid); +$smarty->assign("MOD", $mod_strings); +$smarty->assign("APP", $app_strings); +$smarty->assign("THEME", $theme); +$smarty->assign("IMAGE_PATH",$image_path); +$smarty->assign("MODULE",$currentModule); +$smarty->assign("SINGLE_MOD",'Activity'); +$smarty->assign("BUTTONS",$other_text); +$smarty->assign("NEW_EVENT",$app_strings['LNK_NEW_EVENT']); +$smarty->assign("NEW_TASK",$app_strings['LNK_NEW_TASK']); + +//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,$noofrows); +$smarty->assign('recordListRange',$recordListRangeMsg); + +//Retreive the List View Table Header +if($viewid !='') +$url_string .="&viewname=".$viewid; + +//Cambiado code to add close button in custom vtiger_field +if (($viewid!=0)&&($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'; +} +$listview_header = getListViewHeader($focus,"Calendar",$url_string,$sorder,$order_by,"",$oCustomView); +$smarty->assign("LISTHEADER", $listview_header); + +$listview_header_search=getSearchListHeaderValues($focus,"Calendar",$url_string,$sorder,$order_by,"",$oCustomView); +$smarty->assign("SEARCHLISTHEADER", $listview_header_search); + +$listview_entries = getListViewEntries($focus,"Calendar",$list_result,$navigation_array,"","","EditView","Delete",$oCustomView); +$smarty->assign("LISTENTITY", $listview_entries); +$smarty->assign("SELECT_SCRIPT", $view_script); + +//Added to select Multiple records in multiple pages +$smarty->assign("SELECTEDIDS", vtlib_purify($_REQUEST['selobjs'])); +$smarty->assign("ALLSELECTEDIDS", vtlib_purify($_REQUEST['allselobjs'])); +$smarty->assign("CURRENT_PAGE_BOXES", implode(array_keys($listview_entries),";")); + +$navigationOutput = getTableHeaderSimpleNavigation($navigation_array,$url_string,"Calendar","ListView",$viewid); +$alphabetical = AlphabeticalSearch($currentModule,'ListView','subject','true','basic',"","","","",$viewid); +$fieldnames = getAdvSearchfields($module); +$criteria = getcriteria_options(); +$smarty->assign("CRITERIA", $criteria); +$smarty->assign("FIELDNAMES", $fieldnames); +$smarty->assign("ALPHABETICAL", $alphabetical); +$smarty->assign("NAVIGATION", $navigationOutput); +$category = getParentTab(); +$smarty->assign("CATEGORY",$category); + +$check_button = Button_Check($module); +$smarty->assign("CHECK", $check_button); + +$_SESSION[$currentModule.'_listquery'] = $list_query; + +// Gather the custom link information to display +include_once('vtlib/Vtiger/Link.php'); +$customlink_params = Array('MODULE'=>$currentModule, 'ACTION'=>vtlib_purify($_REQUEST['action']), 'CATEGORY'=> $category); +$smarty->assign('CUSTOM_LINKS', Vtiger_Link::getAllByType(getTabid($currentModule), Array('LISTVIEWBASIC','LISTVIEW'), $customlink_params)); +// END + +if(isset($_REQUEST['ajax']) && $_REQUEST['ajax'] != '') + $smarty->display("ListViewEntries.tpl"); +else + $smarty->display("ActivityListView.tpl"); +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/ListViewPagging.php b/oss/vtiger/trunk/modules/Calendar/ListViewPagging.php new file mode 100644 index 00000000..333f1768 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/ListViewPagging.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/OpenListView.php b/oss/vtiger/trunk/modules/Calendar/OpenListView.php new file mode 100644 index 00000000..27d0e301 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/OpenListView.php @@ -0,0 +1,210 @@ +debug("Entering getPendingActivities() method ..."); + require_once('data/Tracker.php'); + require_once('include/utils/utils.php'); + require_once('user_privileges/default_module_view.php'); + + global $currentModule; + global $singlepane_view; + global $theme; + global $focus; + global $action; + global $adb; + global $app_strings; + global $current_language; + global $current_user; + $current_module_strings = return_module_language($current_language, 'Calendar'); + + $theme_path="themes/".$theme."/"; + $image_path=$theme_path."images/"; + + if($_REQUEST['activity_view']==''){ + $activity_view='today'; + }else{ + $activity_view=vtlib_purify($_REQUEST['activity_view']); + } + + $today = date("Y-m-d", time()); + if($view == 'today'){ + $upcoming_condition = " AND (date_start = '$today' OR vtiger_recurringevents.recurringdate = '$today')"; + $pending_condition = " AND (due_date = '$today' OR vtiger_recurringevents.recurringdate = '$today')"; + }else if($view == 'all'){ + $upcoming_condition = " AND (date_start >= '$today' OR vtiger_recurringevents.recurringdate >= '$today')"; + $pending_condition = " AND (due_date <= '$today' OR vtiger_recurringevents.recurringdate <= '$today')"; + } + + if($mode != 1){ + $list_query = " select vtiger_crmentity.crmid,vtiger_crmentity.smownerid,vtiger_crmentity.". + "setype, vtiger_recurringevents.recurringdate, vtiger_activity.activityid, ". + "vtiger_activity.activitytype, vtiger_activity.date_start, vtiger_activity.due_date,". + "from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=". + "vtiger_activity.activityid LEFT JOIN vtiger_groups ON vtiger_groups.groupid = ". + "vtiger_crmentity.smownerid left outer join vtiger_recurringevents on ". + "vtiger_recurringevents.activityid=vtiger_activity.activityid"; + $list_query .= getNonAdminAccessControlQuery('Calendar',$current_user); + $list_query .= " WHERE vtiger_crmentity.deleted=0 and vtiger_activity.activitytype not in ". + "('Emails') AND ( vtiger_activity.status is NULL OR vtiger_activity.status not in". + "('Completed','Deferred')) and ( vtiger_activity.eventstatus is NULL OR vtiger_activity.". + "eventstatus not in ('Held','Not Held') )".$upcoming_condition; + + }else{ + $list_query = "select vtiger_crmentity.crmid,vtiger_crmentity.smownerid,vtiger_crmentity". + "setype, vtiger_recurringevents.recurringdate, vtiger_activity.activityid, vtiger_activity". + ".activitytype, vtiger_activity.date_start, vtiger_activity.due_date, from vtiger_activity". + "inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid ". + "LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid ". + "left outer join vtiger_recurringevents on vtiger_recurringevents.activityid=". + "vtiger_activity.activityid"; + $list_query .= getNonAdminAccessControlQuery('Calendar',$current_user); + $list_query .= "WHERE vtiger_crmentity.deleted=0 and (vtiger_activity.". + "activitytype not in ('Emails')) AND (vtiger_activity.status is NULL OR vtiger_activity.". + "status not in ('Completed','Deferred')) and (vtiger_activity.eventstatus is NULL OR ". + "vtiger_activity.eventstatus not in ('Held','Not Held')) ".$pending_condition; + + $list_query.= " GROUP BY vtiger_activity.activityid"; + $list_query.= " ORDER BY date_start,time_start ASC"; + $res = $adb->query($list_query); + $noofrecords = $adb->num_rows($res); + $open_activity_list = array(); + $noofrows = $adb->num_rows($res); + if (count($res)>0){ + for($i=0;$i<$noofrows;$i++){ + $open_activity_list[] = Array('name' => $adb->query_result($res,$i,'subject'), + 'id' => $adb->query_result($res,$i,'activityid'), + 'type' => $adb->query_result($res,$i,'activitytype'), + 'module' => $adb->query_result($res,$i,'setype'), + 'date_start' => getDisplayDate($adb->query_result($res,$i,'date_start')), + 'due_date' => getDisplayDate($adb->query_result($res,$i,'due_date')), + 'recurringdate' => getDisplayDate($adb->query_result($res,$i,'recurringdate')), + 'priority' => $adb->query_result($res,$i,'priority'), // Armando L�scher 04.07.2005 -> �priority -> Desc: Get vtiger_priority from db + ); + } + } + + $title=array(); + $title[]=$view; + $title[]='myUpcoPendAct.gif'; + $title[]='home_myact'; + $title[]='showActivityView'; + $title[]='MyUpcumingFrm'; + $title[]='activity_view'; + + $header=array(); + $header[] =$current_module_strings['LBL_LIST_SUBJECT']; + $header[] ='Type'; + + $return_url="&return_module=$currentModule&return_action=DetailView&return_id=" . ((is_object($focus)) ? $focus->id : ""); + $oddRow = true; + $entries=array(); + + foreach($open_activity_list as $event){ + $recur_date=preg_replace('/--/','',$event['recurringdate']); + if($recur_date!=""){ + $event['date_start']=$event['recurringdate']; + } + $font_color_high = "color:#00DD00;"; + $font_color_medium = "color:#DD00DD;"; + + switch ($event['priority']){ + case 'High': + $font_color=$font_color_high; + break; + case 'Medium': + $font_color=$font_color_medium; + break; + default: + $font_color=''; + } + + if($event['type'] != 'Task' && $event['type'] != 'Emails' && $event['type'] != ''){ + $activity_type = 'Events'; + }else{ + $activity_type = 'Task'; + } + } + $entries[$event['id']] = array( + '0' => ''.$event["name"].'', + 'IMAGE' => '', + ); + } + $values=Array('noofactivities'=>$noofrecords,'Title'=>$title,'Header'=>$header,'Entries'=>$entries); + $log->debug("Exiting getPendingActivities method ..."); + return $values; +} + +/** + * Function creates HTML to display ActivityView selection box + * @param string $activity_view - activity view + * return string $ACTIVITY_VIEW_SELECT_OPTION - HTML selection box + */ +function getActivityview($activity_view) +{ + global $log; + $log->debug("Entering getActivityview(".$activity_view.") method ..."); + $today = date("Y-m-d", time()); + + if($activity_view == 'Today') + { + $selected1 = 'selected'; + } + else if($activity_view == 'This Week') + { + $selected2 = 'selected'; + } + else if($activity_view == 'This Month') + { + $selected3 = 'selected'; + } + else if($activity_view == 'This Year') + { + $selected4 = 'selected'; + } + + //constructing the combo values for activities + $ACTIVITY_VIEW_SELECT_OPTION = ''; + + $log->debug("Exiting getActivityview method ..."); + return $ACTIVITY_VIEW_SELECT_OPTION; +} +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/QuickCreate.php b/oss/vtiger/trunk/modules/Calendar/QuickCreate.php new file mode 100644 index 00000000..fbe0170b --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/QuickCreate.php @@ -0,0 +1,19 @@ + \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/RenderRelatedListUI.php b/oss/vtiger/trunk/modules/Calendar/RenderRelatedListUI.php new file mode 100644 index 00000000..2499f82a --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/RenderRelatedListUI.php @@ -0,0 +1,164 @@ +debug("Entering get_duration(".$time_start.",".$duration_hours.",".$duration_minutes.") method ..."); + $time=explode(":",$time_start); + $time_mins = $time[1]; + $time_hrs = $time[0]; + $mins = ($time_mins + $duration_minutes) % 60; + $hrs_min = floor(($time_mins + $duration_minutes) / 60); + if(!isset($hrs)) + $hrs=0; + $hrs = $duration_hours + $hrs_min + $time_hrs; + if($hrs<10) + $hrs=$hrs; + if($mins<10) + $mins="0".$mins; + + $end_time = $hrs .$mins; + $log->debug("Exiting get_duration method ..."); + return $end_time; + } + + /** + * Function to convert time to number + * @param string $time_start - activity start time + * return integer $start_time - time + */ + function time_to_number($time_start) + { + global $log; + $log->debug("Entering time_to_number(".$time_start.") method ..."); + $start_time_array = explode(":",$time_start); + if(preg_match("/^[0]/",$start_time_array[0])) + { + $time_start_hrs=str_replace('0',"",$start_time_array[0]); + } + else + { + $time_start_hrs=$start_time_array[0]; + } + $start_time= $time_start_hrs .$start_time_array[1]; + $log->debug("Exiting time_to_number method ..."); + return $start_time; + } + + /** + * Function to status availability of user + * @param string $owner - ownername + * @param integer $userid - userid + * @param integer $activity_id - activityid + * @param string $avail_date - date in string format + * @param string $activity_start_time - time string + * @param string $activity_end_time - time string + * return string $availability - html img tag in string + */ + function status_availability($owner,$userid,$activity_id,$avail_date,$activity_start_time,$activity_end_time) + { + global $adb,$image_path,$log,$theme; + $log->debug("Entering status_availability(".$owner,$userid.",".$activity_id.",".$avail_date.",".$activity_start_time.",".$activity_end_time.") method ..."); + $avail_flag="false"; + $avail_date=getDBInsertDateValue($avail_date); + if( $owner != $userid) + { + + $usr_query="select activityid,vtiger_activity.date_start,vtiger_activity.due_date, vtiger_activity.time_start,vtiger_activity.duration_hours,vtiger_activity.duration_minutes,vtiger_crmentity.smownerid from vtiger_activity,vtiger_crmentity where vtiger_crmentity.crmid=vtiger_activity.activityid and ('".$avail_date."' like date_start) and vtiger_crmentity.smownerid=? and vtiger_activity.activityid !=? and vtiger_crmentity.deleted=0"; + } + else + { + $usr_query="select activityid,vtiger_activity.date_start,vtiger_activity.due_date, vtiger_activity.time_start,vtiger_activity.duration_hours,vtiger_activity.duration_minutes,vtiger_crmentity.smownerid from vtiger_activity,vtiger_crmentity where vtiger_crmentity.crmid=vtiger_activity.activityid and ('".$avail_date."' like date_start) and vtiger_crmentity.smownerid=? and vtiger_activity.activityid !=? and vtiger_crmentity.deleted=0"; + } + $result_cal=$adb->pquery($usr_query, array($userid, $activity_id)); + $noofrows_cal = $adb->num_rows($result_cal); + $avail_flag="false"; + + if($noofrows_cal!=0) + { + while($row_cal = $adb->fetch_array($result_cal)) + { + $usr_date_start=$row_cal['date_start']; + $usr_due_date=$row_cal['due_date']; + $usr_time_start=$row_cal['time_start']; + $usr_hour_dur=$row_cal['duration_hours']; + $usr_mins_dur=$row_cal['duration_minutes']; + $user_start_time=time_to_number($usr_time_start); + $user_end_time=get_duration($usr_time_start,$usr_hour_dur,$usr_mins_dur); + + if( ( ($user_start_time > $activity_start_time) && ( $user_start_time < $activity_end_time) ) || ( ( $user_end_time > $activity_start_time) && ( $user_end_time < $activity_end_time) ) || ( ( $activity_start_time == $user_start_time ) || ($activity_end_time == $user_end_time) ) ) + { + $availability= 'busy'; + $avail_flag="true"; + $log->info("user start time-- ".$user_start_time."user end time".$user_end_time); + $log->info("Availability ".$availability); + + } + } + } + if($avail_flag!="true") + { + $recur_query="SELECT vtiger_activity.activityid, vtiger_activity.time_start, vtiger_activity.duration_hours, vtiger_activity.duration_minutes , vtiger_crmentity.smownerid, vtiger_recurringevents.recurringid, vtiger_recurringevents.recurringdate as date_start from vtiger_activity inner join vtiger_crmentity on vtiger_activity.activityid = vtiger_crmentity.crmid inner join vtiger_recurringevents on vtiger_activity.activityid=vtiger_recurringevents.activityid where ('".$avail_date."' like vtiger_recurringevents.recurringdate) and vtiger_crmentity.smownerid=? and vtiger_activity.activityid !=? and vtiger_crmentity.deleted=0"; + $result_cal=$adb->pquery($recur_query, array($userid, $activity_id)); + $noofrows_cal = $adb->num_rows($result_cal); + $avail_flag="false"; + + if($noofrows_cal!=0) + { + while($row_cal = $adb->fetch_array($result_cal)) + { + $usr_date_start=$row_cal['date_start']; + $usr_time_start=$row_cal['time_start']; + $usr_hour_dur=$row_cal['duration_hours']; + $usr_mins_dur=$row_cal['duration_minutes']; + $user_start_time=time_to_number($usr_time_start); + $user_end_time=get_duration($usr_time_start,$usr_hour_dur,$usr_mins_dur); + + if( ( ($user_start_time > $activity_start_time) && ( $user_start_time < $activity_end_time) ) || ( ( $user_end_time > $activity_start_time) && ( $user_end_time < $activity_end_time) ) || ( ( $activity_start_time == $user_start_time ) || ($activity_end_time == $user_end_time) ) ) + { + $availability= 'busy'; + $avail_flag="true"; + $log->info("Recurring Events:: user start time-- ".$user_start_time."user end time".$user_end_time); + $log->info("Recurring Events:: Availability ".$availability); + } + } + } + + + } + if($avail_flag == "true") + { + $availability=' '; + } + else + { + $availability=' '; + } + $log->debug("Exiting status_availability method ..."); + return $availability; + + } + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/RepeatEvents.php b/oss/vtiger/trunk/modules/Calendar/RepeatEvents.php new file mode 100644 index 00000000..8badf65e --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/RepeatEvents.php @@ -0,0 +1,186 @@ +date_format) { + case 'dd-mm-yyyy': $format_string = 'd-m-Y H:i'; break; + case 'mm-dd-yyyy': $format_string = 'm-d-Y H:i'; break; + case 'yyyy-mm-dd': $format_string = 'Y-m-d H:i'; break; + } + return date($format_string, self::mktime($timeInYMDHIS)); + } + /** + * Split full timing into date and time part. + */ + static function splittime($fulltiming) { + return split(' ', $fulltiming); + } + /** + * Calculate the time interval to create repeated event entries. + */ + static function getRepeatInterval($type, $frequency, $recurringInfo, $start_date, $limit_date) { + $repeatInterval = Array(); + $starting = self::mktime($start_date); + $limiting = self::mktime($limit_date); + + if($type == 'Daily') { + $count = 0; + while(true) { + ++$count; + $interval = ($count * $frequency); + if(self::mktime(self::nexttime($starting, "+$interval days")) > $limiting) { + break; + } + $repeatInterval[] = $interval; + } + } else if($type == 'Weekly') { + if($recurringInfo->dayofweek_to_rpt == null) { + $count = 0; + $weekcount = 7; + while(true) { + ++$count; + $interval = $count * $weekcount; + if(self::mktime(self::nexttime($starting, "+$interval days")) > $limiting) { + break; + } + $repeatInterval[] = $interval; + } + } else { + $count = 0; + while(true) { + ++$count; + $interval = $count; + $new_timing = self::mktime(self::nexttime($starting, "+$interval days")); + $new_timing_dayofweek = date('N', $new_timing); + if($new_timing > $limiting) { + break; + } + if(in_array($new_timing_dayofweek-1, $recurringInfo->dayofweek_to_rpt)) { + $repeatInterval[] = $interval; + } + } + } + } else if($type == 'Monthly') { + $count = 0; + $avg_monthcount = 30; // TODO: We need to handle month increments precisely! + while(true) { + ++$count; + $interval = $count * $avg_monthcount; + if(self::mktime(self::nexttime($starting, "+$interval days")) > $limiting) { + break; + } + $repeatInterval[] = $interval; + } + } else if($type == 'Yearly') { + $count = 0; + $avg_monthcount = 30; + while(true) { + ++$count; + $interval = $count * $avg_monthcount; + if(self::mktime(self::nexttime($starting, "+$interval days")) > $limiting) { + break; + } + $repeatInterval[] = $interval; + } + } + return $repeatInterval; + } + + /** + * Repeat Activity instance till given limit. + */ + static function repeat($focus) { + + global $log; + $repeat = getrecurringObjValue(); + $frequency = $repeat->recur_freq; + $repeattype= $repeat->recur_type; + + $base_focus = new Activity(); + $base_focus->retrieve_entity_info($focus->id,'Events'); + $base_focus->id = $_REQUEST['record']; + + $base_focus_start = $base_focus->column_fields['date_start'].' '.$base_focus->column_fields['time_start']; + $base_focus_end = $base_focus->column_fields['due_date'].' '.$base_focus->column_fields['time_end']; + + $repeat_limit = getDBInsertDateValue($_REQUEST['calendar_repeat_limit_date']).' '.$base_focus->column_fields['time_start']; + + $repeatIntervals = self::getRepeatInterval($repeattype, $frequency, $repeat, $base_focus_start, $repeat_limit); + + $base_focus_start = self::mktime($base_focus_start); + $base_focus_end = self::mktime($base_focus_end); + + $skip_focus_fields = Array ('record_id', 'createdtime', 'modifiedtime', 'recurringtype'); + + /** Create instance before and reuse */ + $new_focus = new Activity(); + + $numberOfRepeats = count($repeatIntervals); + foreach($repeatIntervals as $index => $interval) { + $new_focus_start_timing = self::nexttime($base_focus_start, "+$interval days"); + $new_focus_start_timing = self::splittime(self::formattime($new_focus_start_timing)); + + $new_focus_end_timing = self::nexttime($base_focus_end, "+$interval days"); + $new_focus_end_timing = self::splittime(self::formattime($new_focus_end_timing)); + + // Reset the new_focus and prepare for reuse + if(isset($new_focus->id)) unset($new_focus->id); + $new_focus->column_fields = array(); + + foreach($base_focus->column_fields as $key=>$value) { + if(in_array($key, $skip_focus_fields)) { + // skip copying few fields + } else if($key == 'date_start') { + $new_focus->column_fields['date_start'] = $new_focus_start_timing[0]; + } else if($key == 'time_start') { + $new_focus->column_fields['time_start'] = $new_focus_start_timing[1]; + } else if($key == 'time_end') { + $new_focus->column_fields['time_end'] = $new_focus_end_timing[1]; + } else if($key == 'due_date') { + $new_focus->column_fields['due_date'] = $new_focus_end_timing[0]; + } else { + $new_focus->column_fields[$key] = $value; + } + } + if($numberOfRepeats > 10 && $index > 10) { + unset($new_focus->column_fields['sendnotification']); + } + $new_focus->save('Calendar'); + } + } +} + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/Save.php b/oss/vtiger/trunk/modules/Calendar/Save.php new file mode 100644 index 00000000..5114e2e9 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/Save.php @@ -0,0 +1,305 @@ +column_fields["activitytype"] = 'Task'; +if(isset($_REQUEST['record'])) +{ + $focus->id = $_REQUEST['record']; + $local_log->debug("id is ".$id); +} +if(isset($_REQUEST['mode'])) +{ + $focus->mode = $_REQUEST['mode']; +} + +if((isset($_REQUEST['change_status']) && $_REQUEST['change_status']) && ($_REQUEST['status']!='' || $_REQUEST['eventstatus']!='')) +{ + $status =''; + $activity_type=''; + $return_id = $focus->id; + if(isset($_REQUEST['status'])) + { + $status = $_REQUEST['status']; + $activity_type = "Task"; + } + elseif(isset($_REQUEST['eventstatus'])) + { + $status = $_REQUEST['eventstatus']; + $activity_type = "Events"; + } + if(isPermitted("Calendar","EditView",$_REQUEST['record']) == 'yes') + { + ChangeStatus($status,$return_id,$activity_type); + } + else + { + echo ""; + echo "
"; + echo "
+ + + + + + + + + +
' >$app_strings[LBL_PERMISSION]
+ $app_strings[LBL_GO_BACK]
+
"; + echo "
";die; + } + $invitee_qry = "select * from vtiger_invitees where activityid=?"; + $invitee_res = $adb->pquery($invitee_qry, array($return_id)); + $count = $adb->num_rows($invitee_res); + if($count != 0) + { + for($j = 0; $j < $count; $j++) + { + $invitees_ids[]= $adb->query_result($invitee_res,$j,"inviteeid"); + + } + $invitees_ids_string = implode(';',$invitees_ids); + sendInvitation($invitees_ids_string,$activity_type,$mail_data['subject'],$mail_data); + } + + +} +else +{ + foreach($focus->column_fields as $fieldname => $val) + { + if(isset($_REQUEST[$fieldname])) + { + if(is_array($_REQUEST[$fieldname])) + $value = $_REQUEST[$fieldname]; + else + $value = trim($_REQUEST[$fieldname]); + $focus->column_fields[$fieldname] = $value; + if(($fieldname == 'notime') && ($focus->column_fields[$fieldname])) + { + $focus->column_fields['time_start'] = ''; + $focus->column_fields['duration_hours'] = ''; + $focus->column_fields['duration_minutes'] = ''; + } + if(($fieldname == 'recurringtype') && ! isset($_REQUEST['recurringcheck'])) + $focus->column_fields['recurringtype'] = '--None--'; + } + } + if(isset($_REQUEST['visibility']) && $_REQUEST['visibility']!= '') + $focus->column_fields['visibility'] = $_REQUEST['visibility']; + else + $focus->column_fields['visibility'] = 'Private'; + + if($_REQUEST['assigntype'] == 'U') { + $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id']; + } elseif($_REQUEST['assigntype'] == 'T') { + $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id']; + } + $focus->save($tab_type); + /* For Followup START -- by Minnie */ + if(isset($_REQUEST['followup']) && $_REQUEST['followup'] == 'on' && $activity_mode == 'Events' && isset($_REQUEST['followup_time_start']) && $_REQUEST['followup_time_start'] != '') + { + $heldevent_id = $focus->id; + $focus->column_fields['subject'] = '[Followup] '.$focus->column_fields['subject']; + $focus->column_fields['date_start'] = $_REQUEST['followup_date']; + $focus->column_fields['due_date'] = $_REQUEST['followup_due_date']; + $focus->column_fields['time_start'] = $_REQUEST['followup_time_start']; + $focus->column_fields['time_end'] = $_REQUEST['followup_time_end']; + $focus->column_fields['eventstatus'] = 'Planned'; + $focus->mode = 'create'; + $focus->save($tab_type); + } + /* For Followup END -- by Minnie */ + $return_id = $focus->id; +} + +if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") + $return_module = vtlib_purify($_REQUEST['return_module']); +else + $return_module = "Calendar"; +if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "") + $return_action = vtlib_purify($_REQUEST['return_action']); +else + $return_action = "DetailView"; +if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "") + $return_id = vtlib_purify($_REQUEST['return_id']); + +$activemode = ""; +if($activity_mode != '') + $activemode = "&activity_mode=".$activity_mode; + +function getRequestData($return_id) +{ + global $adb; + $cont_qry = "select * from vtiger_cntactivityrel where activityid=?"; + $cont_res = $adb->pquery($cont_qry, array($return_id)); + $noofrows = $adb->num_rows($cont_res); + $cont_id = array(); + if($noofrows > 0) { + for($i=0; $i<$noofrows; $i++) { + $cont_id[] = $adb->query_result($cont_res,$i,"contactid"); + } + } + $cont_name = ''; + foreach($cont_id as $key=>$id) { + if($id != '') { + $cont_name .= getContactName($id).', '; + } + } + $cont_name = trim($cont_name,', '); + $mail_data = Array(); + $mail_data['user_id'] = $_REQUEST['assigned_user_id']; + $mail_data['subject'] = $_REQUEST['subject']; + $mail_data['status'] = (($_REQUEST['activity_mode']=='Task')?($_REQUEST['taskstatus']):($_REQUEST['eventstatus'])); + $mail_data['activity_mode'] = $_REQUEST['activity_mode']; + $mail_data['taskpriority'] = $_REQUEST['taskpriority']; + $mail_data['relatedto'] = $_REQUEST['parent_name']; + $mail_data['contact_name'] = $cont_name; + $mail_data['description'] = $_REQUEST['description']; + $mail_data['assign_type'] = $_REQUEST['assigntype']; + $mail_data['group_name'] = getGroupName($_REQUEST['assigned_group_id']); + $mail_data['mode'] = $_REQUEST['mode']; + $value = getaddEventPopupTime($_REQUEST['time_start'],$_REQUEST['time_end'],'24'); + $start_hour = $value['starthour'].':'.$value['startmin'].''.$value['startfmt']; + if($_REQUEST['activity_mode']!='Task') + $end_hour = $value['endhour'] .':'.$value['endmin'].''.$value['endfmt']; + $mail_data['st_date_time'] = getDisplayDate($_REQUEST['date_start'])." ".$start_hour; + $mail_data['end_date_time']=getDisplayDate($_REQUEST['due_date'])." ".$end_hour; + $mail_data['location']=vtlib_purify($_REQUEST['location']); + return $mail_data; +} + +if(isset($_REQUEST['contactidlist']) && $_REQUEST['contactidlist'] != '') +{ + //split the string and store in an array + $storearray = explode (";",$_REQUEST['contactidlist']); + $del_sql = "delete from vtiger_cntactivityrel where activityid=?"; + $adb->pquery($del_sql, array($record)); + $record = $focus->id; + foreach($storearray as $id) + { + if($id != '') + { + + $sql = "insert into vtiger_cntactivityrel values (?,?)"; + $adb->pquery($sql, array($id, $record)); + if(!empty($heldevent_id)) { + $sql = "insert into vtiger_cntactivityrel values (?,?)"; + $adb->pquery($sql, array($id, $heldevent_id)); + } + } + } +} +//Added code to send mail to the assigned to user about the details of the vtiger_activity if sendnotification = on and assigned to user +if($_REQUEST['sendnotification'] == 'on') +{ + $mail_contents = getRequestData($return_id); + getEventNotification($_REQUEST['activity_mode'],$_REQUEST['subject'],$mail_contents); +} + +//code added to send mail to the vtiger_invitees +if(isset($_REQUEST['inviteesid']) && $_REQUEST['inviteesid']!='') +{ + $mail_contents = getRequestData($return_id); + sendInvitation($_REQUEST['inviteesid'],$_REQUEST['activity_mode'],$_REQUEST['subject'],$mail_contents); +} + +//to delete contact account relation while editing event +if(isset($_REQUEST['deletecntlist']) && $_REQUEST['deletecntlist'] != '' && $_REQUEST['mode'] == 'edit') +{ + //split the string and store it in an array + $storearray = explode (";",$_REQUEST['deletecntlist']); + foreach($storearray as $id) + { + if($id != '') + { + $record = $focus->id; + $sql = "delete from vtiger_cntactivityrel where contactid=? and activityid=?"; + $adb->pquery($sql, array($id, $record)); + } + } + +} + +//to delete activity and its parent table relation +if(isset($_REQUEST['del_actparent_rel']) && $_REQUEST['del_actparent_rel'] != '' && $_REQUEST['mode'] == 'edit') +{ + $parnt_id = $_REQUEST['del_actparent_rel']; + $sql= 'delete from vtiger_seactivityrel where crmid=? and activityid=?'; + $adb->pquery($sql, array($parnt_id, $record)); +} + +if(isset($_REQUEST['view']) && $_REQUEST['view']!='') + $view=vtlib_purify($_REQUEST['view']); +if(isset($_REQUEST['hour']) && $_REQUEST['hour']!='') + $hour=vtlib_purify($_REQUEST['hour']); +if(isset($_REQUEST['day']) && $_REQUEST['day']!='') + $day=vtlib_purify($_REQUEST['day']); +if(isset($_REQUEST['month']) && $_REQUEST['month']!='') + $month=vtlib_purify($_REQUEST['month']); +if(isset($_REQUEST['year']) && $_REQUEST['year']!='') + $year=vtlib_purify($_REQUEST['year']); +if(isset($_REQUEST['viewOption']) && $_REQUEST['viewOption']!='') + $viewOption=vtlib_purify($_REQUEST['viewOption']); +if(isset($_REQUEST['subtab']) && $_REQUEST['subtab']!='') + $subtab=vtlib_purify($_REQUEST['subtab']); + +if($_REQUEST['recurringcheck']) { + include_once dirname(__FILE__) . '/RepeatEvents.php'; + Calendar_RepeatEvents::repeat($focus); +} + +//code added for returning back to the current view after edit from list view +if($_REQUEST['return_viewname'] == '') + $return_viewname='0'; +if($_REQUEST['return_viewname'] != '') + $return_viewname=vtlib_purify($_REQUEST['return_viewname']); + +$parenttab=getParentTab(); + +if(!empty($_REQUEST['start'])) { + $page='&start='.vtlib_purify($_REQUEST['start']); +} +if(!empty($_REQUEST['pagenumber'])){ + $page = "&start=".vtlib_purify($_REQUEST['pagenumber']); +} +if($_REQUEST['maintab'] == 'Calendar') + header("Location: index.php?action=".$return_action."&module=".$return_module."&view=".$view."&hour=".$hour."&day=".$day."&month=".$month."&year=".$year."&record=".$return_id."&viewOption=".$viewOption."&subtab=".$subtab."&parenttab=$parenttab"); +else + header("Location: index.php?action=$return_action&module=$return_module$view$hour$day$month$year&record=$return_id$activemode&viewname=$return_viewname$page&parenttab=$parenttab$search"); +?> diff --git a/oss/vtiger/trunk/modules/Calendar/SendReminder.bat b/oss/vtiger/trunk/modules/Calendar/SendReminder.bat new file mode 100644 index 00000000..e148ff49 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/SendReminder.bat @@ -0,0 +1,3 @@ +@echo off +cd ..\..\ +..\..\..\php\php.exe SendReminder.php diff --git a/oss/vtiger/trunk/modules/Calendar/Settings.php b/oss/vtiger/trunk/modules/Calendar/Settings.php new file mode 100644 index 00000000..eaf1e900 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/Settings.php @@ -0,0 +1,42 @@ +0) { + for($i=0;$i<3-$count;$i++) { + $menu_array[] = array(); + } +} + +$smarty->assign("MOD",$mod_strings); +$smarty->assign("APP",$app_strings); +$smarty->assign("IMAGE_PATH", "themes/$theme/images/"); +$smarty->assign('MODULE',$module); +$smarty->assign('MODULE_LBL',getTranslatedString($module)); +$smarty->assign('MENU_ARRAY', $menu_array); + +$smarty->display(vtlib_getModuleTemplate('Vtiger','Settings.tpl')); + +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/TagCloud.php b/oss/vtiger/trunk/modules/Calendar/TagCloud.php new file mode 100644 index 00000000..859b11ff --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/TagCloud.php @@ -0,0 +1,12 @@ + diff --git a/oss/vtiger/trunk/modules/Calendar/TodoSave.php b/oss/vtiger/trunk/modules/Calendar/TodoSave.php new file mode 100644 index 00000000..8bafec3d --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/TodoSave.php @@ -0,0 +1,85 @@ +column_fields["activitytype"] = 'Task'; +} + +if(isset($_REQUEST['record'])) +{ + $focus->id = $_REQUEST['record']; +} +if(isset($_REQUEST['mode'])) +{ + $focus->mode = $_REQUEST['mode']; +} +foreach($focus->column_fields as $fieldname => $val) +{ + if(isset($_REQUEST[$fieldname])) + { + if(is_array($_REQUEST[$fieldname])) + $value = $_REQUEST[$fieldname]; + else + $value = trim($_REQUEST[$fieldname]); + $focus->column_fields[$fieldname] = $value; + } +} + $focus->column_fields["subject"] = $_REQUEST["task_subject"]; + $focus->column_fields["time_start"] = $_REQUEST["task_time_start"]; + if($_REQUEST['task_assigntype'] == 'U') { + $focus->column_fields['assigned_user_id'] = $_REQUEST['task_assigned_user_id']; + } elseif($_REQUEST['task_assigntype'] == 'T') { + $focus->column_fields['assigned_user_id'] = $_REQUEST['task_assigned_group_id']; + } + + $focus->column_fields["taskstatus"] = $_REQUEST["taskstatus"]; + $focus->column_fields["date_start"] = $_REQUEST["task_date_start"]; + $focus->column_fields["due_date"] = $_REQUEST["task_due_date"]; + $focus->column_fields["taskpriority"] = $_REQUEST["taskpriority"]; + $focus->column_fields["parent_id"] = $_REQUEST["task_parent_id"]; + $focus->column_fields["contact_id"] = $_REQUEST["task_contact_id"]; + $focus->column_fields["description"] = $_REQUEST["task_description"]; + if(isset($_REQUEST['task_sendnotification']) && $_REQUEST['task_sendnotification'] != null) + $focus->column_fields["sendnotification"] = $_REQUEST["task_sendnotification"]; + $focus->save($tab_type); + +function getRequestedToData() +{ + $mail_data = Array(); + $mail_data['user_id'] = $_REQUEST["task_assigned_user_id"]; + $mail_data['subject'] = $_REQUEST['task_subject']; + $mail_data['status'] = (($_REQUEST['activity_mode']=='Task')?($_REQUEST['taskstatus']):($_REQUEST['eventstatus'])); + $mail_data['activity_mode'] = $_REQUEST['activity_mode']; + $mail_data['taskpriority'] = $_REQUEST['taskpriority']; + $mail_data['relatedto'] = $_REQUEST['task_parent_name']; + $mail_data['contact_name'] = $_REQUEST['task_contact_name']; + $mail_data['description'] = $_REQUEST['task_description']; + $mail_data['assign_type'] = $_REQUEST['task_assigntype']; + $mail_data['group_name'] = getGroupName($_REQUEST['task_assigned_group_id']); + $mail_data['mode'] = $_REQUEST['task_mode']; + $value = getaddEventPopupTime($_REQUEST['task_time_start'],$_REQUEST['task_time_end'],'24'); + $start_hour = $value['starthour'].':'.$value['startmin'].''.$value['startfmt']; + $mail_data['st_date_time'] = getDisplayDate($_REQUEST['task_date_start'])." ".$start_hour; + $mail_data['end_date_time']=getDisplayDate($_REQUEST['task_due_date']); + return $mail_data; +} + + header("Location: index.php?action=index&module=Calendar&view=".vtlib_purify($_REQUEST['view'])."&hour=".vtlib_purify($_REQUEST['hour'])."&day=".vtlib_purify($_REQUEST['day'])."&month=".vtlib_purify($_REQUEST['month'])."&year=".vtlib_purify($_REQUEST['year'])."&viewOption=".vtlib_purify($_REQUEST['viewOption'])."&subtab=todo&parenttab=".getParentTab()); +?> diff --git a/oss/vtiger/trunk/modules/Calendar/UnifiedSearch.php b/oss/vtiger/trunk/modules/Calendar/UnifiedSearch.php new file mode 100644 index 00000000..14e4cbfa --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/UnifiedSearch.php @@ -0,0 +1,11 @@ + diff --git a/oss/vtiger/trunk/modules/Calendar/addEventUI.php b/oss/vtiger/trunk/modules/Calendar/addEventUI.php new file mode 100644 index 00000000..5d508bb0 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/addEventUI.php @@ -0,0 +1,1106 @@ +id,true); + $to_email = getUserEmailId('id',$current_user->id); + $date_format = parse_calendardate($app_strings['NTC_DATE_FORMAT']); + $taskassignedto = getAssignedTo(9); + $eventassignedto = getAssignedTo(16); +$mysel= vtlib_purify($_REQUEST['view']); +$calendar_arr = Array(); +$calendar_arr['IMAGE_PATH'] = $image_path; +if(empty($mysel)){ + if($current_user->activity_view == "This Year"){ + $mysel = 'year'; + }else if($current_user->activity_view == "This Month"){ + $mysel = 'month'; + }else if($current_user->activity_view == "This Week"){ + $mysel = 'week'; + }else{ + $mysel = 'day'; + } +} +$date_data = array(); +if ( isset($_REQUEST['day'])) +{ + + $date_data['day'] = $_REQUEST['day']; +} + +if ( isset($_REQUEST['month'])) +{ + $date_data['month'] = $_REQUEST['month']; +} + +if ( isset($_REQUEST['week'])) +{ + $date_data['week'] = $_REQUEST['week']; +} + +if ( isset($_REQUEST['year'])) +{ + if ($_REQUEST['year'] > 2037 || $_REQUEST['year'] < 1970) + { + print("".$app_strings['LBL_CAL_LIMIT_MSG'].""); + exit; + } + $date_data['year'] = $_REQUEST['year']; +} + + +if(empty($date_data)) +{ + $data_value=date('Y-m-d H:i:s'); + preg_match('/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/',$data_value,$value); + $date_data = Array( + 'day'=>$value[3], + 'month'=>$value[2], + 'year'=>$value[1], + 'hour'=>$value[4], + 'min'=>$value[5], + ); + +} +$calendar_arr['calendar'] = new Calendar($mysel,$date_data); +$calendar_arr['view'] = $mysel; +if($current_user->hour_format == '') + $calendar_arr['calendar']->hour_format = 'am/pm'; +else + $calendar_arr['calendar']->hour_format = $current_user->hour_format; + +/** Function to construct HTML code for Assigned To field + * @param $assignedto -- Assigned To values :: Type array + * @param $toggletype -- String to different event and task :: Type string + * return $htmlStr -- HTML code in string forat :: Type string + */ +function getAssignedToHTML($assignedto,$toggletype) +{ + global $app_strings; + $userlist = $assignedto[0]; + if(isset($assignedto[1]) && $assignedto[1] != null) + $grouplist = $assignedto[1]; + $htmlStr = ''; + $check = 1; + foreach($userlist as $key_one=>$arr) + { + foreach($arr as $sel_value=>$value) + { + if($value != '') + $check=$check*0; + else + $check=$check*1; + } + } + if($check == 0) + { + $select_user='checked'; + $style_user='display:block'; + $style_group='display:none'; + } + else + { + $select_group='checked'; + $style_user='display:none'; + $style_group='display:block'; + } + if($toggletype == 'task') + $htmlStr .= ' '.$app_strings['LBL_USER']; + else + $htmlStr .= ' '.$app_strings['LBL_USER']; + if($grouplist != '') + { + if($toggletype == 'task') + $htmlStr .= ' '.$app_strings['LBL_GROUP']; + else + $htmlStr .= ' '.$app_strings['LBL_GROUP']; + } + if($toggletype == 'task') + { + $htmlStr .= ' + '; + } + $htmlStr .= getUserslist(); + $htmlStr .= ' + '; + if($grouplist != '') + { + if($toggletype == 'task') + { + $htmlStr .= ' + '; + } + $htmlStr .= getGroupslist(); + $htmlStr .= ' + '; + } + return $htmlStr; +} + +?> + + + + + + + + + + + +
+ + + + +
+ + id,'eventstatus') == '0') { ?> + - + - + + + - + - + + - + +
+
+ + +
+ +column_fields['is_admin']=='on') + $Res = $adb->pquery("select * from vtiger_activitytype",array()); + else + { + $role_id=$current_user->roleid; + $subrole = getRoleSubordinates($role_id); + if(count($subrole)> 0) + { + $roleids = $subrole; + array_push($roleids, $role_id); + } + else + { + $roleids = $role_id; + } + + if (count($roleids) > 1) { + $Res=$adb->pquery("select distinct activitytype from vtiger_activitytype inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_activitytype.picklist_valueid where roleid in (". generateQuestionMarks($roleids) .") and picklistid in (select picklistid from vtiger_activitytype) order by sortid asc",array($roleids)); + } else { + $Res=$adb->pquery("select distinct activitytype from vtiger_activitytype inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_activitytype.picklist_valueid where roleid = ? and picklistid in (select picklistid from vtiger_activitytype) order by sortid asc",array($role_id)); + } + } + $eventlist=''; + for($i=0; $i<$adb->num_rows($Res);$i++) + { + $eventlist = $adb->query_result($Res,$i,'activitytype'); +?> + + + +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
 
: + + + onclick=checkgroup(); checked>  + +
+ + + +
 
+    + + +
+
+
+ + +
+ + + + +
+ + id,'taskstatus') == '0') { ?> + - + - + + + + - + - + + - + + +
+
+ diff --git a/oss/vtiger/trunk/modules/Calendar/calendarLayout.php b/oss/vtiger/trunk/modules/Calendar/calendarLayout.php new file mode 100644 index 00000000..80c35023 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/calendarLayout.php @@ -0,0 +1,2183 @@ +debug("Entering calendar_layout() method"); + $cal_header = array (); + if (isset($param_arr['size']) && $param_arr['size'] == 'small') + $param_arr['calendar']->show_events = false; + + $cal_header['view'] = $param_arr['view']; + $cal_header['IMAGE_PATH'] = $param_arr['IMAGE_PATH']; + $cal_header['calendar'] = $param_arr['calendar']; + $eventlabel = $mod_strings['LBL_EVENTS']; + $todolabel = $mod_strings['LBL_TODOS']; + //if $param_arr['size'] is set to 'small', get small(mini) calendar + if(isset($param_arr['size']) && $param_arr['size'] == 'small') + { + get_mini_calendar($param_arr); + } + else + { + // User Select Customization + $onlyForUserParam = "onlyforuser=" . calendarview_getSelectedUserId(); + // END + + //To differentiate selected subtab from unselected one - Starts + if($subtab == 'event') + { + $eventtab_class = 'dvtSelectedCell'; + $todotab_class = 'dvtUnSelectedCell'; + $event_anchor = $eventlabel; + // Added for User Based CustomView for Calendar module + $todo_anchor = "date_time->get_date_str()."&viewOption=".$viewBox."&subtab=todo&parenttab=".$category."&$onlyForUserParam'>".$todolabel.""; + + } + elseif($subtab == 'todo') + { + $eventtab_class = 'dvtUnSelectedCell'; + $todotab_class = 'dvtSelectedCell'; + // Added User Based CustomView for Calendar module + $event_anchor = "date_time->get_date_str()."&viewOption=".$viewBox."&subtab=event&parenttab=".$category."&$onlyForUserParam'>".$eventlabel.""; + $todo_anchor = $todolabel; + } + //Ends + //To get calendar header and its links(like Day,Week,Month,Year and etc.) + get_cal_header_tab($cal_header,$viewBox,$subtab); + $subheader = ""; + $subheader .=<< + + + + + + +
+ + + + + + + + + +
 $event_anchor $todo_anchor 
+
+EOQ; + echo $subheader; + if($viewBox == 'hourview' && $subtab == 'event') + { + get_cal_header_data($param_arr,$viewBox,$subtab); + getHourView($param_arr); + } + elseif($viewBox == 'listview' && $subtab == 'event') + { + get_cal_header_data($param_arr,$viewBox,$subtab); + getEventListView($param_arr); + } + elseif($subtab == 'todo') + { + $todo_list = ""; + $todo_list .= getTodosListView($param_arr,'',$subtab); + $todo_list .= '

'; + echo $todo_list; + } + } + + $cal_log->debug("Exiting calendar_layout() method"); + +} + +/** + * Function creates HTML to display small(mini) Calendar + * @param array $cal - collection of objects and strings + */ +function get_mini_calendar(& $cal){ + global $current_user,$adb,$cal_log,$mod_strings,$theme; + $category = getParentTab(); + $cal_log->debug('Entering get_mini_calendar() method...'); + $count = 0; + //To decide number of rows(weeks) in a month + if ($cal['calendar']->month_array[$cal['calendar']->slices[35]]->start_time->month != $cal['calendar']->date_time->month) { + $rows = 5; + } else { + $rows = 6; + } + $minical = ""; + $minical .= " + + + "; + $minical .= ""; + $minical .= ""; + //To display days in week + $minical .= ''; + for ($i = 0; $i < 7; $i ++){ + $weekday = $mod_strings['cal_weekdays_short'][$i]; + $minical .= ''; + } + $minical .= ""; + $event_class = ''; + $class = ''; + for ($i = 0; $i < $rows; $i++){ + $minical .= ""; + + //calculate blank days for first week + for ($j = 0; $j < 7; $j ++){ + $cal['slice'] = $cal['calendar']->month_array[$cal['calendar']->slices[$count]]; + $class = dateCheck($cal['slice']->start_time->get_formatted_date()); + if($j == 0){ + $minical .= ""; + } + + //To differentiate day having events from other days + if(count($cal['slice']->activities) != 0 && ($cal['slice']->start_time->get_formatted_date() == $cal['slice']->activities[0]->start_time->get_formatted_date())){ + $event_class = 'class="eventDay"'; + }else{ + $event_class = ''; + } + //To differentiate current day from other days + if($class != '' ){ + $class = 'class="'.$class.'"'; + }else{ + $class = $event_class; + } + + //To display month dates + if ($cal['slice']->start_time->getMonth() == $cal['calendar']->date_time->getMonth()){ + $minical .= ""; + }else{ + $minical .= ""; + } + $count++; + } + $minical .= ''; + } + $minical .= "
 ".get_previous_cal($cal)." "; + $minical .= "date_time->get_date_str()."&parenttab=".$category."'>".display_date($cal['view'],$cal['calendar']->date_time)." ".get_next_cal($cal)." +
'.$mod_strings['LBL_WEEK'].''.$weekday.'
start_time->get_date_str()."&parenttab=".$category."'>".$cal['slice']->start_time->week.""; + $minical .= "getView()."".$cal['slice']->start_time->get_date_str()."&parenttab=".$category."'>"; + $minical .= $cal['slice']->start_time->get_Date()."
"; + echo $minical; + $cal_log->debug("Exiting get_mini_calendar() method..."); +} + +/** + * Function creates HTML to display Calendar Header and its Links + * @param array $header - collection of objects and strings + * @param string $viewBox - string 'listview' or 'hourview' or may be empty. if 'listview' means Events ListView.if 'hourview' means Events HourView. if empty means get Todos ListView + * @param string $subtab - string 'todo' or 'event'. if 'todo' means Todos View else Events View + */ +function get_cal_header_tab(& $header,$viewBox,$subtab) +{ + global $mod_strings,$cal_log; + $category = getParentTab(); + $cal_log->debug("Entering get_cal_header_tab() method..."); + $tabhtml = ""; + $count = 1; + include_once 'modules/Calendar/addEventUI.php'; + include_once 'modules/Calendar/header.php'; + $eventlabel = $mod_strings['LBL_EVENTS']; + $todolabel = $mod_strings['LBL_TODOS']; + $div = " + +
+ "; + echo $div; + $tabhtml .= ""; + $links = array ('day','week','month','year'); + //To differentiate the selected link from unselected links + foreach ($links as $link) + { + if ($header['view'] == $link) + { + $class = 'calSel'; + $anchor = $mod_strings["LBL_".$header['calendar']->getCalendarView($link)]; + } + else + { + $class = 'calUnSel'; + $anchor = "date_time->get_date_str()."&viewOption=".$viewBox."&subtab=".$subtab."&parenttab=".$category."'>".$mod_strings["LBL_".$header['calendar']->getCalendarView($link)].""; + } + + if($count == 1) + $tabhtml .= ""; + else + $tabhtml .= ""; + $count++; + } + //To get Navigation(next&previous) links and display Date info + $tabhtml .= ""; + $tabhtml .= ""; + $tabhtml .= ""; + $tabhtml .= ""; + $tabhtml .= ""; + echo $tabhtml; + $cal_log->debug("Exiting get_cal_header_tab() method..."); +} + +/** + * Function creates HTML to display number of Events, Todos and pending list in calendar under header(Eg:Total Events : 5, 2 Pending / Total To Dos: 4, 1 Pending) + * @param array $cal_arr - collection of objects and strings + * @param string $viewBox - string 'listview' or 'hourview'. if 'listview' means Events ListView.if 'hourview' means Events HourView. + */ +function get_cal_header_data(& $cal_arr,$viewBox,$subtab) +{ + global $mod_strings,$cal_log,$current_user,$adb,$theme; + $cal_log->debug("Entering get_cal_header_data() method..."); + global $current_user,$app_strings; + $date_format = $current_user->date_format; + $format = $cal_arr['calendar']->hour_format; + $hour_startat = timeString(array('hour'=>date('H:i',(time()+(5*60))),'minute'=>0),'24'); + $hour_endat = timeString(array('hour'=>date('H:i',(time() + (60 * 60))),'minute'=>0),'24'); + $time_arr = getaddEventPopupTime($hour_startat,$hour_endat,$format); + $temp_ts = $cal_arr['calendar']->date_time->ts; + //To get date in user selected format + $temp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$temp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$temp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $temp_ts)):('')))); + + if($current_user->column_fields['is_admin']=='on') + $Res = $adb->pquery("select * from vtiger_activitytype",array()); + else + { + $roleid=$current_user->roleid; + $subrole = getRoleSubordinates($roleid); + if(count($subrole)> 0) + { + $roleids = $subrole; + array_push($roleids, $roleid); + } + else + { + $roleids = $roleid; + } + + if (count($roleids) > 1) { + $Res=$adb->pquery("select distinct activitytype from vtiger_activitytype inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_activitytype.picklist_valueid where roleid in (". generateQuestionMarks($roleids) .") and picklistid in (select picklistid from vtiger_activitytype) order by sortid asc", array($roleids)); + } else { + $Res=$adb->pquery("select distinct activitytype from vtiger_activitytype inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_activitytype.picklist_valueid where roleid = ? and picklistid in (select picklistid from vtiger_activitytype) order by sortid asc", array($roleid)); + } + } + + $eventlist=''; + for($i=0; $i<$adb->num_rows($Res);$i++) + { + $eventlist .= $adb->query_result($Res,$i,'activitytype').";"; + } + + $headerdata = ""; + $headerdata .=" +
+
+ +
".$anchor."".$anchor." + + + "; + $tabhtml .= ""; + $tabhtml .= " +
".get_previous_cal($header,$viewBox,$subtab)." + ".display_date($header['view'],$header['calendar']->date_time)."".get_next_cal($header,$viewBox,$subtab)." +
+
view."".$header['calendar']->date_time->get_date_str()."&viewOption=".$viewBox."&subtab=".$subtab."&parenttab=".$category."\");' src='".$header['IMAGE_PATH']."btnL3Calendar.gif' alt='".$mod_strings['LBL_OPENCAL']."...' title='".$mod_strings['LBL_OPENCAL']."...' align='absmiddle' border='0'>view."".$header['calendar']->date_time->get_date_str()."&viewOption=".$viewBox."&subtab=".$subtab."&parenttab=".$category."\");' src='".$header['IMAGE_PATH']."tbarSettings.gif' alt='".$mod_strings['LBL_SETTINGS']."' title='".$mod_strings['LBL_SETTINGS']."' align='absmiddle' border='0'>".$app_strings['Calendar']."
+ "; + if(isPermitted("Calendar","EditView") == "yes") + { + $headerdata .=" + "; + } + else + { + $headerdata .=""; + } + $headerdata .=" + + +
 
+
+ ".$mod_strings['LBL_ADD']." + +
 ";//USER SELECT CUSTOMIZATION + $headerdata .= getEventInfo($cal_arr,'listcnt'); + $headerdata .= "
".$mod_strings['LBL_VIEW']." : ";//USER SELECT CUSTOMIZATION + $view_options = getEventViewOption($cal_arr,$viewBox); + + // User Select Customization + $view_options .= calendarview_getUserSelectOptions( calendarview_getSelectedUserId() ); + // END + + $headerdata .=$view_options."
+
"; + echo $headerdata; + $cal_log->debug("Exiting get_cal_header_data() method..."); +} + +/** + * Function creates HTML select statement to display View selection box + * @param array $cal - collection of objects and strings + * @param string $viewBox - string 'listview' or 'hourview'. if 'listview' means get Events ListView.if 'hourview' means get Events HourView. + * return string $view - html selection box + */ +function getEventViewOption(& $cal,$viewBox) +{ + global $mod_strings,$cal_log; + $category = getParentTab(); + if($viewBox == 'listview') + { + $list_sel = 'selected'; + $hr_sel = ''; + } + else + { + $list_sel = ''; + $hr_sel = 'selected'; + } + $cal_log->debug("Entering getEventViewOption() method..."); + $view = "view."'> + date_time->hour."'> + date_time->day."'> + date_time->week."'> + date_time->month."'> + date_time->year."'> + + + + + + + "; + $cal_log->debug("Exiting getEventViewOption() method..."); + return $view; +} + +/** + * Function creates HTML anchor tag to get previous-day/week/month/year view + * @param array $cal - collection of objects and strings + * @param string $viewBox - string 'listview' or 'hourview' or may be empty. if 'listview' means previous link in Events ListView.if 'hourview' means previous link in Events HourView. if empty means previous link in Todos ListView + * @param string $subtab - string 'todo' or 'event' or may be empty. if 'todo' means Todos View. if 'event' means Events View. if empty means small calendar view. + * return string $link - html tags in string format + */ +function get_previous_cal(& $cal,$viewBox='',$subtab='') +{ + global $mod_strings,$cal_log,$theme; + $category = getParentTab(); + $cal_log->debug("Entering get_previous_cal() method..."); + if(isset($cal['size']) && $cal['size'] == 'small') + { + $link = "view."".$cal['calendar']->get_datechange_info('prev')."&parenttab=".$category."\")'>"; + } + else + { + $link = "view."".$cal['calendar']->get_datechange_info('prev')."&viewOption=".$viewBox."&subtab=".$subtab."&parenttab=".$category."&onlyforuser=".calendarview_getSelectedUserId()."' onclick='VtigerJS_DialogBox.block();return true;'>"; + } + $cal_log->debug("Exiting get_previous_cal() method..."); + return $link; +} + +/** + * Function creates HTML anchor tag to get next-day/week/month/year view + * @param array $cal - collection of objects and strings + * @param string $viewBox - string 'listview' or 'hourview' or may be empty. if 'listview' means next link in Events ListView.if 'hourview' means next link in Events HourView. if empty means next link in Todos ListView + * @param string $subtab - string 'todo' or 'event' or may be empty. if 'todo' means Todos View. if 'event' means Events View. if empty means small calendar view. + * return string $link - html tags in string format + */ +function get_next_cal(& $cal,$viewBox='',$subtab='') +{ + global $mod_strings,$cal_log,$theme; + $category = getParentTab(); + $cal_log->debug("Entering get_next_cal() method..."); + if(isset($cal['size']) && $cal['size'] == 'small') + { + $link = "view."".$cal['calendar']->get_datechange_info('next')."&parenttab=".$category."\")' >"; + } + else + { + $link = "view."".$cal['calendar']->get_datechange_info('next')."&viewOption=".$viewBox."&subtab=".$subtab."&parenttab=".$category."&onlyforuser=".calendarview_getSelectedUserId()."' onclick='VtigerJS_DialogBox.block();return true;'>"; + } + $cal_log->debug("Exiting get_next_cal() method..."); + return $link; + +} + +/** + * Function to get date info depending upon on the calendar view(Eg: 21 July 2000) + * @param string $view - calendar view(day/week/month/year) + * @param array $date_time - contains DateTime object + * return string $label - date info(Eg for dayview : 13 July 2000) + */ +function display_date($view,$date_time) +{ + global $cal_log; + $cal_log->debug("Entering display_date() method..."); + if ($view == 'day') + { + //$label = $date_time->getdayofWeek()." "; + $label = $date_time->get_Date()." "; + $label .= $date_time->getmonthName()." "; + $label .= $date_time->year; + $cal_log->debug("Exiting display_date() method..."); + return $label; + } + elseif ($view == 'week') + { + $week_start = $date_time->getThisweekDaysbyIndex(0); + $week_end = $date_time->getThisweekDaysbyIndex(6); + $label = $week_start->get_Date()." "; + $label .= $week_start->getmonthName()." "; + $label .= $week_start->year; + $label .= " - "; + $label .= $week_end->get_Date()." "; + $label .= $week_end->getmonthName()." "; + $label .= $week_end->year; + $cal_log->debug("Exiting display_date() method..."); + return $label; + } + + elseif ($view == 'month') + { + $label = $date_time->getmonthName()." "; + $label .= $date_time->year; + $cal_log->debug("Exiting display_date() method..."); + return $label; + } + elseif ($view == 'year') + { + $cal_log->debug("Exiting display_date() method..."); + return $date_time->year; + } + +} +/** + * Function to get css class name for date + * @param string $slice_date - date + * returns string - css class name or empty string + */ +function dateCheck($slice_date) +{ + global $cal_log; + $cal_log->debug("Entering dateCheck() method..."); + $today = date('Y-m-d'); + if($today == $slice_date) + { + $cal_log->debug("Exiting dateCheck() method..."); + //css class for day having event(s) + return 'currDay'; + } + else + { + $cal_log->debug("Exiting dateCheck() method..."); + return ''; + } +} + +/** + * Function to construct respective calendar layout depends on the calendar view + * @param array $view - collection of objects and strings + */ +function getHourView(& $view) +{ + global $cal_log,$theme; + $hourview_layout = ''; + $cal_log->debug("Entering getHourView() method..."); + $hourview_layout .= '
+
'; + + if($view['view'] == 'day') + $hourview_layout .= getDayViewLayout($view); + elseif($view['view'] == 'week') + $hourview_layout .= getWeekViewLayout($view); + elseif($view['view'] == 'month') + $hourview_layout .= getMonthViewLayout($view); + elseif($view['view'] == 'year') + $hourview_layout .= getYearViewLayout($view); + else + die("view:".$view['view']." is not defined"); + + $hourview_layout .= '
+ '; + $hourview_layout .= '
+ + + + + + + + +
'; + echo $hourview_layout; + $cal_log->debug("Exiting getHourView() method..."); +} + +/** + * Fuction constructs Events ListView depends on the view + * @param array $cal - collection of objects and strings + * @param string $mode - string 'listcnt' or empty. if empty means get Events ListView else get total no. of events and no. of pending events Info. + * returns string $activity_list - total no. of events and no. of pending events Info(Eg: Total Events : 2, 1 Pending). + */ +function getEventListView(& $cal,$mode='') +{ + global $cal_log,$theme; + $list_view = ""; + $cal_log->debug("Entering getEventListView() method..."); + if($cal['calendar']->view == 'day') + { + $start_date = $end_date = $cal['calendar']->date_time->get_formatted_date(); + } + elseif($cal['calendar']->view == 'week') + { + $start_date = $cal['calendar']->slices[0]; + $end_date = $cal['calendar']->slices[6]; + } + elseif($cal['calendar']->view == 'month') + { + $start_date = $cal['calendar']->date_time->getThismonthDaysbyIndex(0); + $end_date = $cal['calendar']->date_time->getThismonthDaysbyIndex($cal['calendar']->date_time->daysinmonth - 1); + $start_date = $start_date->get_formatted_date(); + $end_date = $end_date->get_formatted_date(); + } + elseif($cal['calendar']->view == 'year') + { + $start_date = $cal['calendar']->date_time->getThisyearMonthsbyIndex(0); + $end_date = $cal['calendar']->date_time->get_first_day_of_changed_year('increment'); + $start_date = $start_date->get_formatted_date(); + $end_date = $end_date->get_formatted_date(); + } + else + { + die("view:".$cal['calendar']->view." is not defined"); + } + //if $mode value is empty means get Events list in array format else get the count of total events and pending events in array format. + if($mode != '') + { + $activity_list = getEventList($cal, $start_date, $end_date,$mode); + $cal_log->debug("Exiting getEventListView() method..."); + return $activity_list; + } + else + { + $ret_arr = getEventList($cal, $start_date, $end_date,$mode); + $activity_list = $ret_arr[0]; + $navigation_array = $ret_arr[1]; + } + //To get Events listView + $list_view .="
"; + $list_view .=constructEventListView($cal,$activity_list,$navigation_array); + $list_view .="
+ "; + $list_view .="
+ + + + + + + + +
"; + echo $list_view; + $cal_log->debug("Exiting getEventListView() method..."); +} + + +/** + * Fuction constructs Todos ListView depends on the view + * @param array $cal - collection of objects and strings + * @param string $check - string 'listcnt' or empty. if empty means get Todos ListView else get total no. of Todos and no. of pending todos Info. + * returns string $todo_list - total no. of todos and no. of pending todos Info(Eg: Total Todos : 2, 1 Pending). + */ +function getTodosListView($cal, $check='',$subtab='') +{ + global $cal_log,$theme; + $list_view = ""; + $cal_log->debug("Entering getTodosListView() method..."); + if($cal['calendar']->view == 'day') + { + $start_date = $end_date = $cal['calendar']->date_time->get_formatted_date(); + } + elseif($cal['calendar']->view == 'week') + { + $start_date = $cal['calendar']->slices[0]; + $end_date = $cal['calendar']->slices[6]; + } + elseif($cal['calendar']->view == 'month') + { + $start_date = $cal['calendar']->date_time->getThismonthDaysbyIndex(0); + $end_date = $cal['calendar']->date_time->getThismonthDaysbyIndex($cal['calendar']->date_time->daysinmonth - 1); + $start_date = $start_date->get_formatted_date(); + $end_date = $end_date->get_formatted_date(); + } + elseif($cal['calendar']->view == 'year') + { + $start_date = $cal['calendar']->date_time->getThisyearMonthsbyIndex(0); + $end_date = $cal['calendar']->date_time->get_first_day_of_changed_year('increment'); + $start_date = $start_date->get_formatted_date(); + $end_date = $end_date->get_formatted_date(); + } + else + { + die("view:".$cal['calendar']->view." is not defined"); + } + //if $check value is empty means get Todos list in array format else get the count of total todos and pending todos in array format. + if($check != '') + { + $todo_list = getTodoList($cal, $start_date, $end_date,$check); + $cal_log->debug("Exiting getTodosListView() method..."); + return $todo_list; + } + else + { + $ret_arr = getTodoList($cal, $start_date, $end_date,$check); + $todo_list = $ret_arr[0]; + $navigation_arr = $ret_arr[1]; + } + $cal_log->debug("Exiting getTodosListView() method..."); + $list_view .="
"; + //To get Todos listView + $list_view .= constructTodoListView($todo_list,$cal,$subtab,$navigation_arr); + $list_view .="
+ + + + + + + + + + "; + echo $list_view; +} + +/** + * Function creates HTML to display Calendar DayView + * @param array $cal - collections of objects and strings. + * return string $dayview_layout - html tags in string format + */ +function getDayViewLayout(& $cal) +{ + global $current_user,$app_strings,$cal_log,$adb; + $no_of_rows = 1; + $cal_log->debug("Entering getDayViewLayout() method..."); + $date_format = $current_user->date_format; + $day_start_hour = $cal['calendar']->day_start_hour; + $day_end_hour = $cal['calendar']->day_end_hour; + $format = $cal['calendar']->hour_format; + $show_complete_view = false; + if(!empty($_REQUEST['complete_view'])){ + $show_complete_view =true; + } + $dayview_layout = ''; + $dayview_layout .= ' '; + $dayview_layout .= ' +
+ '; + if(!empty($show_complete_view)) { + $dayview_layout .= ''; + $day_start_hour = 0; + $day_end_hour = 23; + } else { + $dayview_layout .= ''; + } + for($j=0;$j<24;$j++) + { + $slice = $cal['calendar']->slices[$j]; + $act = $cal['calendar']->day_slice[$slice]->activities; + if(!empty($act)) + { + $temprows = count($act); + $no_of_rows = ($no_of_rows>$temprows)?$no_of_rows:$temprows; + } + } + for($i=$day_start_hour;$i<=$day_end_hour;$i++) + { + $time = array('hour'=>$i,'minute'=>0); + $sub_str = timeString($time,$format); + $y = $i+1; + $hour_startat = timeString(array('hour'=>$i,'minute'=>0),'24'); + $hour_endat = timeString(array('hour'=>$y,'minute'=>0),'24'); + $time_arr = getaddEventPopupTime($hour_startat,$hour_endat,$format); + $temp_ts = $cal['calendar']->date_time->ts; + $sttemp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$temp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$temp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $temp_ts)):('')))); + if($i != 23) + { + $endtemp_date = $sttemp_date; + } + else + { + $addday = $temp_ts + (1 * 24 * 60 * 60); + $endtemp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$addday)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$addday)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $addday)):('')))); + } + + $js_string = ""; + if(isPermitted("Calendar","EditView") == "yes") + $js_string = 'onClick="fnvshobj(this,\'addEvent\'); gshow(\'addEvent\',\'Call\',\''.$sttemp_date.'\',\''.$endtemp_date.'\',\''.$time_arr['starthour'].'\',\''.$time_arr['startmin'].'\',\''.$time_arr['startfmt'].'\',\''.$time_arr['endhour'].'\',\''.$time_arr['endmin'].'\',\''.$time_arr['endfmt'].'\',\'hourview\',\'event\')"'; + $dayview_layout .= ' + '; + //To display events in Dayview + $dayview_layout .= getdayEventLayer($cal,$cal['calendar']->slices[$i],$no_of_rows); + $dayview_layout .= ''; + } + $dayview_layout .= '
  
  
'.$sub_str.'
+
'; + $cal_log->debug("Exiting getDayViewLayout() method..."); + return $dayview_layout; +} + +/** + * Function creates HTML to display Calendar WeekView + * @param array $cal - collections of objects and strings. + * return string $weekview_layout - html tags in string format + */ +function getWeekViewLayout(& $cal) +{ + global $current_user,$app_strings,$cal_log,$theme; + $category = getParentTab(); + $cal_log->debug("Entering getWeekViewLayout() method..."); + $date_format = $current_user->date_format; + $day_start_hour = $cal['calendar']->day_start_hour; + $day_end_hour = $cal['calendar']->day_end_hour; + $format = $cal['calendar']->hour_format; + $show_complete_view = false; + if(!empty($_REQUEST['complete_view'])){ + $show_complete_view =true; + } + $weekview_layout = ''; + $weekview_layout .= ''; + for ($col=0;$col<=7;$col++) + { + if($col==0) { + $weekview_layout .= ''; + if(!empty($show_complete_view)) { + $weekview_layout .= ''; + $day_start_hour = 0; + $day_end_hour = 23; + } else { + $weekview_layout .= ''; + } + } else { + //To display Days in Week + $cal['slice'] = $cal['calendar']->week_array[$cal['calendar']->slices[$col-1]]; + $date = $cal['calendar']->date_time->getThisweekDaysbyIndex($col-1); + $day = $date->getdayofWeek_inshort(); + $weekview_layout .= ''; + } + } + $weekview_layout .= '
'; + $weekview_layout .= ''; + $weekview_layout .= $date->get_Date().' - '.$day; + $weekview_layout .= ""; + $weekview_layout .= '
'; + $weekview_layout .= ''; + //To display Hours in User selected format + for($i=$day_start_hour;$i<=$day_end_hour;$i++) + { + $count = $i; + $hour_startat = timeString(array('hour'=>$i,'minute'=>0),'24'); + $hour_endat = timeString(array('hour'=>($i+1),'minute'=>0),'24'); + $time_arr = getaddEventPopupTime($hour_startat,$hour_endat,$format); + $weekview_layout .= ''; + for ($column=1;$column<=1;$column++) + { + $time = array('hour'=>$i,'minute'=>0); + $sub_str = timeString($time,$format); + + $weekview_layout .= ''; + } + for ($column=0;$column<=6;$column++) + { + $temp_ts = $cal['calendar']->week_array[$cal['calendar']->slices[$column]]->start_time->ts; + $sttemp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$temp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$temp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $temp_ts)):('')))); + if($i != 23) + $endtemp_date = $sttemp_date; + else + { + $endtemp_ts = $cal['calendar']->week_array[$cal['calendar']->slices[$column+1]]->start_time->ts; + $endtemp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$endtemp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$endtemp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $endtemp_ts)):('')))); + } + + $weekview_layout .= ''; + $count = $count+24; + } + $weekview_layout .= ''; + } + $weekview_layout .= '
'; + $weekview_layout .=$sub_str; + $weekview_layout .= ''; + $weekview_layout .= ''; + //To display events in WeekView + $weekview_layout .=getweekEventLayer($cal,$cal['calendar']->week_hour_slices[$count]); + $weekview_layout .= '
'; + return $weekview_layout; + $cal_log->debug("Exiting getWeekViewLayout() method..."); + +} + +/** + * Function creates HTML to display Calendar MonthView + * @param array $cal - collections of objects and strings. + * return string $monthview_layout - html tags in string format + */ +function getMonthViewLayout(& $cal) +{ + global $current_user,$app_strings,$cal_log,$theme; + $category = getParentTab(); + $cal_log->debug("Entering getMonthViewLayout() method..."); + $date_format = $current_user->date_format; + $count = 0; + //To get no. of rows(weeks) in month + if ($cal['calendar']->month_array[$cal['calendar']->slices[35]]->start_time->month != $cal['calendar']->date_time->month) { + $rows = 5; + } else { + $rows = 6; + } + $format = $cal['calendar']->hour_format; + $hour_startat = timeString(array('hour'=>date('H:i'),'minute'=>0),'24'); + $hour_endat = timeString(array('hour'=>date('H:i',(time() + (60 * 60))),'minute'=>0),'24'); + $time_arr = getaddEventPopupTime($hour_startat,$hour_endat,$format); + $monthview_layout = ''; + $monthview_layout .= ''; + //To display days in week + for ($i = 0; $i < 7; $i ++) + { + $first_row = $cal['calendar']->month_array[$cal['calendar']->slices[$i]]; + $weekday = $first_row->start_time->getdayofWeek(); + $monthview_layout .= ''; + } + $monthview_layout .= '
'.$weekday.'
'; + $monthview_layout .= ' '; + $cnt = 0; + for ($i = 0; $i < $rows; $i ++) + { + $monthview_layout .= ''; + for ($j = 0; $j < 7; $j ++) + { + $temp_ts = $cal['calendar']->month_array[$cal['calendar']->slices[$count]]->start_time->ts; + $temp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$temp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$temp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $temp_ts)):('')))); + if($cal['calendar']->day_start_hour != 23) + $endtemp_date = $temp_date; + else + { + $endtemp_ts = $cal['calendar']->month_array[$cal['calendar']->slices[$count+1]]->start_time->ts; + $endtemp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$endtemp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$endtemp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $endtemp_ts)):('')))); + } + $cal['slice'] = $cal['calendar']->month_array[$cal['calendar']->slices[$count]]; + $monthclass = dateCheck($cal['slice']->start_time->get_formatted_date()); + if($monthclass != '') + $monthclass = 'calSel'; + else + $monthclass = 'dvtCellLabel'; + //to display dates in month + if ($cal['slice']->start_time->getMonth() == $cal['calendar']->date_time->getMonth()) + { + $monthview_layout .= ''; + } + else + { + $monthview_layout .= ''; + } + $count++; + } + $monthview_layout .= ''; + $monthview_layout .= ''; + for ($j = 0; $j < 7; $j ++) + { + $monthview_layout .= ''; + $cnt++; + } + $monthview_layout .= ''; + } + $monthview_layout .= '
'; + $monthview_layout .= ''; + $monthview_layout .= $cal['slice']->start_time->get_Date(); + $monthview_layout .= ''; + $monthview_layout .= ' 
'; + $monthview_layout .= getmonthEventLayer($cal,$cal['calendar']->slices[$cnt]); + $monthview_layout .= '
'; + return $monthview_layout; + $cal_log->debug("Exiting getMonthViewLayout() method..."); + +} + +/** + * Function creates HTML to display Calendar YearView + * @param array $cal - collections of objects and strings. + * return string $yearview_layout - html tags in string format + */ +function getYearViewLayout(& $cal) +{ + global $mod_strings,$cal_log; + $category = getParentTab(); + $cal_log->debug("Entering getYearViewLayout() method..."); + $yearview_layout = ''; + $yearview_layout .= ''; + $count = 0; + //year view divided as 4 rows and 3 columns + for($i=0;$i<4;$i++) + { + $yearview_layout .= ''; + for($j=0;$j<3;$j++) + { + $cal['slice'] = $cal['calendar']->year_array[$cal['calendar']->slices[$count]]; + $yearview_layout .= ''; + } + $yearview_layout .= '
+ + + + '; + for($w=0;$w<7;$w++) + { + $yearview_layout .= ''; + } + $yearview_layout .= ''; + list($_3rdyear,$_3rdmonth,$_3rddate) = explode("-",$cal['calendar']->month_day_slices[$count][35]); + list($_2ndyear,$_2ndmonth,$_2nddate) = explode("-",$cal['calendar']->month_day_slices[$count][6]); + //to get no. of rows(weeks) in month + if ($_3rdmonth != $_2ndmonth) { + $rows = 5; + } else { + $rows = 6; + } + $cnt = 0; + $date_stack = Array(); + for ($k = 0; $k < 5; $k ++) + { + $yearview_layout .= ''; + for ($mr = 0; $mr < 7; $mr ++) + { + list($_1styear,$_1stmonth,$_1stdate) = explode("-",$cal['calendar']->month_day_slices[$count][$cnt]); + if(count($cal['slice']->activities) != 0) + { + for($act_count = 0;$act_countactivities);$act_count++) + { + array_push($date_stack,$cal['slice']->activities[$act_count]->start_time->get_formatted_date()); + } + } + if(in_array($cal['calendar']->month_day_slices[$count][$cnt],$date_stack)) + $event_class = 'class="eventDay"'; + else + $event_class = ''; + if($_1stmonth == $_2ndmonth) + $curclass = dateCheck($cal['calendar']->month_day_slices[$count][$cnt]); + if($curclass != '') + { + $class = 'class="'.$curclass.'"'; + $curclass = ''; + } + else + { + $class = $event_class; + $event_class = ''; + } + $date = $_1stdate + 0; + $month = $_1stmonth + 0; + $yearview_layout .= ''; + $cnt++; + } + $yearview_layout .= ''; + } + $yearview_layout .= ' +
+ + '.$cal['slice']->start_time->month_inlong.' + +
'.$mod_strings['cal_weekdays_short'][$w].'
'; + if($rows == 6 && $k==0) + { + list($tempyear,$tempmonth,$tempdate) = explode("-",$cal['calendar']->month_day_slices[$count][35+$mr]); + if($tempmonth == $_2ndmonth) + $yearview_layout .= ''.$tempdate; + } + if($_1stmonth == $_2ndmonth) + { + $yearview_layout .= ''.$date; + } + $yearview_layout .= '
+ + + '; + $count++; + } + $yearview_layout .= '
'; + return $yearview_layout; + $cal_log->debug("Exiting getYearViewLayout() method..."); + + +} + +/** + * Function creates HTML To display events in day view + * @param array $cal - collection of objects and strings + * @param string $slice - date:time(eg: 2006-07-13:10) + * returns string $eventlayer - hmtl in string format + */ +function getdayEventLayer(& $cal,$slice,$rows) +{ + global $mod_strings,$cal_log,$listview_max_textlength,$adb,$current_user,$theme; + $category = getParentTab(); + $cal_log->debug("Entering getdayEventLayer() method..."); + $eventlayer = ''; + $arrow_img_name = ''; + $rows = $rows + 1; + $last_colwidth = 100 / $rows; + $width = 100 / $rows ; + $act = $cal['calendar']->day_slice[$slice]->activities; + if(!empty($act)) + { + for($i=0;$iday_slice[$slice]->start_time->hour.'_'.$i; + $subject = $act[$i]->subject; + $id = $act[$i]->record; + if($listview_max_textlength && (strlen($subject)>$listview_max_textlength)) + $subject = substr($subject,0,$listview_max_textlength)."..."; + $format = $cal['calendar']->hour_format; + $duration_hour = $act[$i]->duration_hour; + $duration_min =$act[$i]->duration_minute; + $user = $act[$i]->owner; + $priority = $act[$i]->priority; + if($duration_min != '00') + $rowspan = $duration_hour+$rowspan; + elseif($duration_hour != '0') + { + $rowspan = $duration_hour; + } + $row_cnt = $rowspan; + $start_hour = timeString($act[$i]->start_time,$format); + $end_hour = timeString($act[$i]->end_time,$format); + $account_name = $act[$i]->accountname; + $eventstatus = $act[$i]->eventstatus; + $color = $act[$i]->color; + $image = vtiger_imageurl($act[$i]->image_name, $theme); + if($act[$i]->recurring) + $recurring = ''; + else + $recurring = ' '; + $height = $rowspan * 75; + $javacript_str = ''; + $idShared = "normal"; if($act[$i]->shared) $idShared = "shared"; + /*if($eventstatus != 'Held') + {*/ + if($idShared == "normal") + { + if(isPermitted("Calendar","EditView") == "yes" || isPermitted("Calendar","Delete") == "yes") + $javacript_str = 'onMouseOver="cal_show(\''.$arrow_img_name.'\');" onMouseOut="fnHide_Event(\''.$arrow_img_name.'\');"'; + $action_str = ''; + } + else + { + $javacript_str = ''; + $eventlayer .= ' '; + } + $eventlayer .= ''; + + $visibility_query=$adb->pquery('SELECT visibility from vtiger_activity where activityid=?',array($id)); + $visibility = $adb->query_result($visibility_query,0,'visibility'); + $user_query = $adb->pquery("SELECT vtiger_crmentity.smownerid,vtiger_users.user_name from vtiger_crmentity,vtiger_users where crmid=? and vtiger_crmentity.smownerid=vtiger_users.id", array($id)); + $userid = $adb->query_result($user_query,0,"smownerid"); + $assigned_role_query=$adb->pquery("select roleid from vtiger_user2role where userid=?",array($userid)); + $assigned_role_id = $adb->query_result($assigned_role_query,0,"roleid"); + $role_list = $adb->pquery("SELECT * from vtiger_role WHERE parentrole LIKE '". formatForSqlLike($current_user->column_fields['roleid']) . formatForSqlLike($assigned_role_id) ."'",array()); + $is_shared = $adb->pquery("SELECT * from vtiger_sharedcalendar where userid=? and sharedid=?",array($userid,$current_user->id)); + if(($current_user->column_fields['is_admin']!='on' && $adb->num_rows($role_list)==0 && (($adb->num_rows($is_shared)==0 && ($visibility=='Public' || $visibility=='Private')) || $visibility=='Private')) && $current_user->column_fields['user_name']!=$user) + { + $eventlayer .= '
'; + } + else{ + $eventlayer .= '
'; + } + $eventlayer .= ' + + + '; + $eventlayer .= ''; + + if(($current_user->column_fields['is_admin']!='on' && $adb->num_rows($role_list)==0 && (($adb->num_rows($is_shared)==0 && ($visibility=='Public' || $visibility=='Private')) || $visibility=='Private')) && $current_user->column_fields['user_name']!=$user) + { + $eventlayer .= ''; + }else{ + $eventlayer .= ' + + '; + } $eventlayer .= '
'.$start_hour.' - '.$end_hour.'
'.$recurring.''.$user.' - '.$mod_strings['LBL_BUSY'].''.$subject.'
'; + if($act[$i]->shared) + $eventlayer .= ''; + else + $eventlayer .= ' '; + $eventlayer .= '('.$user.' | '.getTranslatedString($eventstatus).' | '.getTranslatedString($priority).')
'.$action_str.' 
'; + } + $eventlayer .= ' '; + } + else + { + $eventlayer .= ' '; + $eventlayer .= ' '; + } + $cal_log->debug("Exiting getdayEventLayer() method..."); + return $eventlayer; +} + +/** + * Function creates HTML To display events in week view + * @param array $cal - collection of objects and strings + * @param string $slice - date:time(eg: 2006-07-13:10) + * returns string $eventlayer - hmtl in string format + */ +function getweekEventLayer(& $cal,$slice) +{ + global $mod_strings,$cal_log,$listview_max_textlength,$adb,$current_user,$theme; + $category = getParentTab(); + $cal_log->debug("Entering getweekEventLayer() method..."); + $eventlayer = ''; + $arrow_img_name = ''; + $act = $cal['calendar']->week_slice[$slice]->activities; + if(!empty($act)) + { + for($i=0;$iweek_slice[$slice]->start_time->get_formatted_date().'_'.$act[$i]->start_time->hour.'_'.$i; + /* fix given by dartagnanlaf END --integrated by Minnie */ + $id = $act[$i]->record; + $subject = $act[$i]->subject; + if($listview_max_textlength && (strlen($subject)>$listview_max_textlength)) + $subject = substr($subject,0,$listview_max_textlength)."..."; + $format = $cal['calendar']->hour_format; + $start_hour = timeString($act[$i]->start_time,$format); + $end_hour = timeString($act[$i]->end_time,$format); + $account_name = $act[$i]->accountname; + $eventstatus = $act[$i]->eventstatus; + $user = $act[$i]->owner; + $priority = $act[$i]->priority; + $image = vtiger_imageurl($act[$i]->image_name, $theme); + $idShared = "normal"; if($act[$i]->shared) $idShared = "shared"; + if($act[$i]->recurring) + $recurring = ''; + else + $recurring = ' '; + $color = $act[$i]->color; + if($idShared == "normal") + { + if(isPermitted("Calendar","EditView") == "yes" || isPermitted("Calendar","Delete") == "yes") + $javacript_str = 'onMouseOver="cal_show(\''.$arrow_img_name.'\');" onMouseOut="fnHide_Event(\''.$arrow_img_name.'\');"'; + $action_str = ''; + } + else + { + $javacript_str = ''; + $eventlayer .= ' '; + } + + $visibility_query=$adb->pquery('SELECT visibility from vtiger_activity where activityid=?',array($id)); + $visibility = $adb->query_result($visibility_query,0,'visibility'); + $user_query = $adb->pquery("SELECT vtiger_crmentity.smownerid,vtiger_users.user_name from vtiger_crmentity,vtiger_users where crmid=? and vtiger_crmentity.smownerid=vtiger_users.id", array($id)); + $userid = $adb->query_result($user_query,0,"smownerid"); + $assigned_role_query=$adb->pquery("select roleid from vtiger_user2role where userid=?",array($userid)); + $assigned_role_id = $adb->query_result($assigned_role_query,0,"roleid"); + $role_list = $adb->pquery("SELECT * from vtiger_role WHERE parentrole LIKE '". formatForSqlLike($current_user->column_fields['roleid']) . formatForSqlLike($assigned_role_id) ."'",array()); + $is_shared = $adb->pquery("SELECT * from vtiger_sharedcalendar where userid=? and sharedid=?",array($userid,$current_user->id)); + if(($current_user->column_fields['is_admin']!='on' && $adb->num_rows($role_list)==0 && (($adb->num_rows($is_shared)==0 && ($visibility=='Public' || $visibility=='Private')) || $visibility=='Private')) && $current_user->column_fields['user_name']!=$user) + { + $eventlayer .= '
'; + } + else{ + $eventlayer .= '
'; + } + + $eventlayer .=' + + + + + + '; + if(($current_user->column_fields['is_admin']!='on' && $adb->num_rows($role_list)==0 && (($adb->num_rows($is_shared)==0 && ($visibility=='Public' || $visibility=='Private')) || $visibility=='Private')) && $current_user->column_fields['user_name']!=$user) + { + $eventlayer .= ''; + }else{//CALUSER CUST END + $eventlayer .= ' + + '; + } + $eventlayer .= '
'.$start_hour.' - '.$end_hour.'
'.$recurring.''.$user.'-'.$mod_strings['LBL_BUSY'].''.$subject.'
'; + if($act[$i]->shared) + $eventlayer .= ''; + else + $eventlayer .= ' '; + $eventlayer .= '('.$user.' | '.getTranslatedString($eventstatus).' | '.getTranslatedString($priority).')
'.$action_str.' 

'; + } + $cal_log->debug("Exiting getweekEventLayer() method..."); + return $eventlayer; + } + +} + +/** + * Function creates HTML To display events in month view + * @param array $cal - collection of objects and strings + * @param string $slice - date(eg: 2006-07-13) + * returns string $eventlayer - hmtl in string format + */ +function getmonthEventLayer(& $cal,$slice) +{ + global $mod_strings,$cal_log,$adb,$current_user,$theme; + $category = getParentTab(); + $cal_log->debug("Entering getmonthEventLayer() method..."); + $eventlayer = ''; + $arrow_img_name = ''; + $act = $cal['calendar']->month_array[$slice]->activities; + if(!empty($act)) + { + $no_of_act = count($act); + if($no_of_act>2) + { + $act_row = 2; + $remin_list = $no_of_act - $act_row; + } + else + { + $act_row = $no_of_act; + $remin_list = null; + } + for($i=0;$i<$act_row;$i++) + { + $arrow_img_name = 'event'.$cal['calendar']->month_array[$slice]->start_time->hour.'_'.$i; + $id = $act[$i]->record; + $subject = $act[$i]->subject; + if(strlen($subject)>10) + $subject = substr($subject,0,10)."..."; + $format = $cal['calendar']->hour_format; + $start_hour = timeString($act[$i]->start_time,$format); + $end_hour = timeString($act[$i]->end_time,$format); + $account_name = $act[$i]->accountname; + $image = vtiger_imageurl($act[$i]->image_name, $theme); + $color = $act[$i]->color; + //Added for User Based Customview for Calendar Module + $visibility_query=$adb->pquery('SELECT visibility from vtiger_activity where activityid=?',array($id)); + $visibility = $adb->query_result($visibility_query,0,'visibility'); + $user_query = $adb->pquery("SELECT vtiger_crmentity.smownerid,vtiger_users.user_name from vtiger_crmentity,vtiger_users where crmid=? and vtiger_crmentity.smownerid=vtiger_users.id", array($id)); + $userid = $adb->query_result($user_query,0,"smownerid"); + $username = $adb->query_result($user_query,0,"user_name"); + $assigned_role_query=$adb->pquery("select roleid from vtiger_user2role where userid=?",array($userid)); + $assinged_role_id = $adb->query_result($assigned_role_query,0,"roleid"); + $role_list = $adb->pquery("SELECT * from vtiger_role WHERE parentrole LIKE '". formatForSqlLike($current_user->column_fields['roleid']) . formatForSqlLike($assinged_role_id) ."'",array()); + $is_shared = $adb->pquery("SELECT * from vtiger_sharedcalendar where userid=? and sharedid=?",array($userid,$current_user->id)); + + if(($current_user->column_fields['is_admin']!='on' && $adb->num_rows($role_list)==0 && (($adb->num_rows($is_shared)==0 && ($visibility=='Public' || $visibility=='Private')) || $visibility=='Private')) && $current_user->id != $userid) + { + $eventlayer .='
+  '.$username.' - '.$mod_strings["LBL_BUSY"].' +

'; + }else{ + $eventlayer .='
'; + } + } + + if($remin_list != null) + { + $eventlayer .=''; + } + $cal_log->debug("Exiting getmonthEventLayer() method..."); + return $eventlayer; + } +} + +/** + * 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..."); + + //modified query to fix the ticket #5014 & #5180 + $and = "AND (((vtiger_activity.date_start >= ? AND vtiger_activity.due_date <= ?) + AND (vtiger_recurringevents.activityid is NULL)) + OR (vtiger_recurringevents.recurringdate BETWEEN ? AND ?))"; + + $query = "SELECT vtiger_groups.groupname, vtiger_users.user_name,vtiger_crmentity.smownerid, vtiger_crmentity.crmid, + vtiger_activity.* FROM vtiger_activity + INNER JOIN vtiger_crmentity + ON vtiger_crmentity.crmid = vtiger_activity.activityid + LEFT JOIN vtiger_groups + ON vtiger_groups.groupid = vtiger_crmentity.smownerid + LEFT JOIN vtiger_users + ON vtiger_users.id = vtiger_crmentity.smownerid + LEFT OUTER JOIN vtiger_recurringevents + ON vtiger_recurringevents.activityid = vtiger_activity.activityid + WHERE vtiger_crmentity.deleted = 0 + AND (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 + + $params = $info_params = array($start_date, $end_date, $start_date, $end_date); + 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 = ? + OR vtiger_groups.groupid in (". generateQuestionMarks($groupids) .")) + GROUP BY vtiger_activity.activityid"; + } else { + $com_q = " AND vtiger_crmentity.smownerid = ? + GROUP 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"; + + if( $adb->dbType == "pgsql"){ + $query = fixPostgresQuery($query, $log, 0); + } + + + + $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"); + $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']; + $date_start = $adb->query_result($result,$i,"date_start"); + $due_date = $adb->query_result($result,$i,"due_date"); + $element['starttime'] = getDisplayDate($date_start).' '.$start_hour; + $element['endtime'] = getDisplayDate($due_date).' '.$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 != '') + { + $contactname = getContactName($contact_id); + $contact_data = "".$contactname.","; + } + $more_link = "[".$mod_strings['LBL_MORE']."...]"; + $type = $adb->query_result($result,$i,"activitytype"); + if($type == 'Call') + $image_tag = " ".$app_strings['Call']; + else if($type == 'Meeting') + $image_tag = " ".$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'] ="date_time->hour."\",\"".$calendar['calendar']->date_time->get_formatted_date()."\",\"event\");' src='" . vtiger_imageurl('cal_event.jpg', $theme). "' border='0'>"; + } + else + { + if(isPermitted("Calendar","EditView") == "yes" || isPermitted("Calendar","Delete")=="yes") + $element['action']=""; + } + 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'] = "".$app_strings['LBL_NOT_ACCESSIBLE'].""; + + + }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; +} + +/** + * 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'); + + $query = "SELECT vtiger_groups.groupname, vtiger_users.user_name, vtiger_crmentity.crmid, vtiger_cntactivityrel.contactid, + vtiger_activity.* FROM vtiger_activity + INNER JOIN vtiger_crmentity + ON vtiger_crmentity.crmid = vtiger_activity.activityid + LEFT JOIN vtiger_cntactivityrel + ON vtiger_cntactivityrel.activityid = vtiger_activity.activityid + LEFT JOIN vtiger_groups + ON vtiger_groups.groupid = vtiger_crmentity.smownerid + LEFT JOIN vtiger_users + ON vtiger_users.id = vtiger_crmentity.smownerid"; + $query .= getNonAdminAccessControlQuery('Calendar',$current_user); + $query .= "WHERE vtiger_crmentity.deleted = 0 AND vtiger_activity.activitytype = 'Task'". + " AND (vtiger_activity.date_start BETWEEN ? AND ?)"; + + $list_query = $query." AND vtiger_crmentity.smownerid = " . $current_user->id; + // 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 = ? + OR 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); + } + + $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"; + + if( $adb->dbType == "pgsql"){ + $query = fixPostgresQuery( $query, $log, 0); + } + + $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 = "".$subject.""; + $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'] = "".$contact_name.""; + }*/ + 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'] = "".$app_strings['LBL_NOT_ACCESSIBLE'].""; + + + }else + $element['status'] = getTranslatedString(decode_html($taskstatus)); + + + } + if(isPermitted("Calendar","EditView") == "yes" || isPermitted("Calendar","Delete") == "yes") + $element['action'] ="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 to get number of Events and Todos Info + * @param array $cal - collection of objects and strings + * @param string $mode - string 'listcnt' or may be empty. if empty means get Events/Todos ListView else get total events/todos and no. of pending events/todos Info. + * return array $event_todo_info - collection of events/todos info. + */ +function getEventInfo(& $cal, $mode) +{ + global $mod_strings,$cal_log; + $cal_log->debug("Entering getEventInfo() method..."); + $event = Array(); + $event['event']=getEventListView($cal, $mode); + $event_info = ""; + $event_info .= $mod_strings['LBL_TOTALEVENTS']." ".$event['event']['totalevent']; + if($event['event']['pendingevent'] != null) + $event_info .= ", ".$event['event']['pendingevent']." ".$mod_strings['LBL_PENDING']; + $cal_log->debug("Exiting getEventInfo() method..."); + + return $event_info; +} + +function getTodoInfo(& $cal, $mode) +{ + global $mod_strings,$cal_log; + $cal_log->debug("Entering getTodoInfo() method..."); + $todo = Array(); + $todo['todo'] = getTodosListView($cal, $mode); + $todo_info = ""; + $todo_info .=$mod_strings['LBL_TOTALTODOS']." ".$todo['todo']['totaltodo']; + if($todo['todo']['pendingtodo'] != null) + $todo_info .= ", ".$todo['todo']['pendingtodo']." ".$mod_strings['LBL_PENDING']; + $cal_log->debug("Exiting getTodoInfo() method..."); + + return $todo_info; +} + + +/** + * Function creates HTML to display Events ListView + * @param array $entry_list - collection of strings(Event Information) + * return string $list_view - html tags in string format + */ +function constructEventListView(& $cal,$entry_list,$navigation_array='') +{ + global $mod_strings,$app_strings,$adb,$cal_log,$current_user,$theme; + $cal_log->debug("Entering constructEventListView() method..."); + $format = $cal['calendar']->hour_format; + $date_format = $current_user->date_format; + $hour_startat = timeString(array('hour'=>date('H:i'),'minute'=>0),'24'); + $hour_endat = timeString(array('hour'=>date('H:i',(time() + (60 * 60))),'minute'=>0),'24'); + $time_arr = getaddEventPopupTime($hour_startat,$hour_endat,$format); + $temp_ts = $cal['calendar']->date_time->ts; + //to get date in user selected date format + $temp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$temp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$temp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $temp_ts)):('')))); + if($cal['calendar']->day_start_hour != 23) + $endtemp_date = $temp_date; + else + { + $endtemp_ts = $temp_ts + (1 * 24 * 60 * 60); + $endtemp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$endtemp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$endtemp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $endtemp_ts)):('')))); + } + $list_view = ""; + $start_datetime = $app_strings['LBL_START_DATE_TIME']; + $end_datetime = $app_strings['LBL_END_DATE_TIME']; + //Events listview header labels + $header = Array('0'=>'#', + '1'=>$start_datetime, + '2'=>$end_datetime, + '3'=>$mod_strings['LBL_EVENTTYPE'], + '4'=>$mod_strings['LBL_EVENTDETAILS'] + ); + $header_width = Array('0'=>'5%', + '1'=>'15%', + '2'=>'15%', + '3'=>'10%', + '4'=>'33%' + ); + /*if(getFieldVisibilityPermission('Events',$current_user->id,'parent_id') == '0') + { + array_push($header,$mod_strings['LBL_RELATEDTO']); + array_push($header_width,'15%'); + }*/ + if(isPermitted("Calendar","EditView") == "yes" || isPermitted("Calendar","Delete") == "yes") + { + array_push($header,$mod_strings['LBL_ACTION']); + array_push($header_width,'10%'); + } + if(getFieldVisibilityPermission('Events',$current_user->id,'eventstatus') == '0') + { + array_push($header,$mod_strings['LBL_STATUS']); + array_push($header_width,'$10%'); + } + array_push($header,$mod_strings['LBL_ASSINGEDTO']); + array_push($header_width,'15%'); + + $list_view .=" + "; + $header_rows = count($header); + + $navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string,"Calendar","index"); + + if($navigationOutput != '') + { + $list_view .= ""; + } + $list_view .= ""; + for($i=0;$i<$header_rows;$i++) + { + $list_view .=""; + } + $list_view .=""; + $rows = count($entry_list); + if($rows != 0) + { + for($i=0;$i"; + + foreach($entry_list[$i] as $key=>$entry) + { + $assigned_role_query=$adb->pquery("select vtiger_user2role.roleid,vtiger_user2role.userid from vtiger_user2role INNER JOIN vtiger_users where vtiger_users.id=vtiger_user2role.userid and vtiger_users.user_name=?",array($entry_list[$i]['assignedto'])); + $assigned_user_role_id = $adb->query_result($assigned_role_query,0,"roleid"); + $assigned_user_id = $adb->query_result($assigned_role_query,0,"userid"); + $role_list = $adb->pquery("SELECT * from vtiger_role WHERE parentrole LIKE '". formatForSqlLike($current_user->column_fields['roleid']) . formatForSqlLike($assigned_user_role_id) ."'",array()); + $is_shared = $adb->pquery("SELECT * from vtiger_sharedcalendar where userid=? and sharedid=?",array($assigned_user_id,$current_user->id)); + if($key!='visibility'){ + if(($key=='eventdetail'|| $key=='action') && ($current_user->column_fields['is_admin']!='on' && $adb->num_rows($role_list)==0 && (($adb->num_rows($is_shared)==0 && ($entry_list[$i]['visibility']=='Public' || $entry_list[$i]['visibility']=='Private')) || $entry_list[$i]['visibility']=='Private')) && $current_user->column_fields['user_name']!=$entry_list[$i]['assignedto']){ + if($key=='eventdetail') + $list_view .=""; + else + $list_view .=""; + }else + $list_view .=""; + } + } + $list_view .=""; + } + } + else + { + $list_view .=""; + } + $list_view .="
"; + $list_view .= "".$navigationOutput."
".$header[$i]."
".$entry_list[$i]['assignedto']." - ".$mod_strings['LBL_BUSY']."".$app_strings['LBL_NOT_ACCESSIBLE']."$entry
+ "; + $list_view .="
+ + + + + + "; + //checking permission for Create/Edit Operation + if(isPermitted("Calendar","EditView") == "yes") + { + $list_view .=""; + } + else + { + $list_view .=""; + } + $list_view .=" +
+ ".$app_strings['LBL_NO']." ".$app_strings['Events']." ".$app_strings['LBL_FOUND']." !
".$app_strings['LBL_YOU_CAN_CREATE']." ".$app_strings['LBL_AN']." ".$app_strings['Event']." ".$app_strings['LBL_NOW'].". ".$app_strings['LBL_CLICK_THE_LINK'].":
+   -".$app_strings['LBL_CREATE']." ".$app_strings['LBL_AN']." ".$app_strings['Event']."
+
".$app_strings['LBL_YOU_ARE_NOT_ALLOWED_TO_CREATE']." ".$app_strings['LBL_AN']." ".$app_strings['Event']."
+
"; + $list_view .="
"; + $cal_log->debug("Exiting constructEventListView() method..."); + return $list_view; +} + +/** + * Function creates HTML to display Todos ListView + * @param array $todo_list - collection of strings(Todo Information) + * @param array $cal - collection of objects and strings + * return string $list_view - html tags in string format + */ +function constructTodoListView($todo_list,$cal,$subtab,$navigation_array='') +{ + global $mod_strings,$cal_log,$adb,$theme; + $cal_log->debug("Entering constructTodoListView() method..."); + global $current_user,$app_strings; + $date_format = $current_user->date_format; + $format = $cal['calendar']->hour_format; + $hour_startat = timeString(array('hour'=>date('H:i'),'minute'=>0),'24'); + $hour_endat = timeString(array('hour'=>date('H:i',(time() + (60 * 60))),'minute'=>0),'24'); + $time_arr = getaddEventPopupTime($hour_startat,$hour_endat,$format); + $temp_ts = $cal['calendar']->date_time->ts; + //to get date in user selected date format + $temp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$temp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$temp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $temp_ts)):('')))); + if($cal['calendar']->day_start_hour != 23) + $endtemp_date = $temp_date; + else + { + $endtemp_ts = $temp_ts + (1 * 24 * 60 * 60); + $endtemp_date = (($date_format == 'dd-mm-yyyy')?(date('d-m-Y',$endtemp_ts)):(($date_format== 'mm-dd-yyyy')?(date('m-d-Y',$endtemp_ts)):(($date_format == 'yyyy-mm-dd')?(date('Y-m-d', $endtemp_ts)):('')))); + } + $list_view = ""; + //labels of listview header + if($cal['view'] == 'day') + { + $colspan = 9; + $header = Array('0'=>'#','1'=>$mod_strings['LBL_TIME'],'2'=>$mod_strings['LBL_LIST_DUE_DATE'], + '3'=>$mod_strings['LBL_TODO']); + $header_width = Array('0'=>'5%','1'=>'10%','2'=>'10%','3'=>'38%',); + /*if(getFieldVisibilityPermission('Calendar',$current_user->id,'parent_id') == '0') + { + array_push($header,$mod_strings['LBL_RELATEDTO']); + array_push($header_width,'15%'); + } + if(getFieldVisibilityPermission('Calendar',$current_user->id,'contact_id') == '0') + { + array_push($header,$mod_strings['LBL_CONTACT_NAME']); + array_push($header_width,'15%'); + }*/ + if(getFieldVisibilityPermission('Calendar',$current_user->id,'taskstatus') == '0') + { + array_push($header,$mod_strings['LBL_STATUS']); + array_push($header_width,'10%'); + } + + if(isPermitted("Calendar","EditView") == "yes" || isPermitted("Calendar","Delete") == "yes") + { + array_push($header,$mod_strings['LBL_ACTION']); + array_push($header_width,'10%'); + } + array_push($header,$mod_strings['LBL_ASSINGEDTO']); + array_push($header_width,'15%'); + } + else + { + $colspan = 10; + $header = Array('0'=>'#', + '1'=>$mod_strings['LBL_TIME'], + '2'=>$mod_strings['LBL_START_DATE'], + '3'=>$mod_strings['LBL_DUE_DATE'], + '4'=>$mod_strings['LBL_TODO'] + ); + $header_width = Array('0'=>'5%', + '1'=>'10%', + '2'=>'10%', + '3'=>'10%', + '4'=>'28%' + ); + /*if(getFieldVisibilityPermission('Calendar',$current_user->id,'parent_id') == '0') + { + array_push($header,$mod_strings['LBL_RELATEDTO']); + array_push($header_width,'15%'); + } + if(getFieldVisibilityPermission('Calendar',$current_user->id,'contact_id') == '0') + { + array_push($header,$mod_strings['LBL_CONTACT_NAME']); + array_push($header_width,'15%'); + }*/ + if(getFieldVisibilityPermission('Calendar',$current_user->id,'taskstatus') == '0') + { + array_push($header,$mod_strings['LBL_STATUS']); + array_push($header_width,'10%'); + } + if(isPermitted("Calendar","EditView") == "yes" || isPermitted("Calendar","Delete") == "yes") + { + array_push($header,$mod_strings['LBL_ACTION']); + } + array_push($header,$mod_strings['LBL_ASSINGEDTO']); + array_push($header_width,'15%'); + + } + if($current_user->column_fields['is_admin']=='on') + $Res = $adb->pquery("select * from vtiger_activitytype",array()); + else + { + $roleid=$current_user->roleid; + $subrole = getRoleSubordinates($roleid); + if(count($subrole)> 0) + { + $roleids = $subrole; + array_push($roleids, $roleid); + } + else + { + $roleids = $roleid; + } + + if (count($roleids) > 1) { + $Res=$adb->pquery("select distinct activitytype from vtiger_activitytype inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_activitytype.picklist_valueid where roleid in (". generateQuestionMarks($roleids) .") and picklistid in (select picklistid from vtiger_activitytype) order by sortid asc",array($roleids)); + } else { + $Res=$adb->pquery("select distinct activitytype from vtiger_activitytype inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_activitytype.picklist_valueid where roleid = ? and picklistid in (select picklistid from vtiger_activitytype) order by sortid asc",array($roleid)); + } + } + $eventlist=''; + for($i=0; $i<$adb->num_rows($Res);$i++) + { + $eventlist .= $adb->query_result($Res,$i,'activitytype').";"; + } + + $list_view .=" + "; + //checking permission for Create/Edit Operation + if(isPermitted("Calendar","EditView") == "yes") + { + $list_view .=" + "; + } + else + { + $list_view .=""; + } + $list_view .=" + + +
 
+ ".$mod_strings['LBL_ADD']." +
 ".getTodoInfo($cal,'listcnt')."  
+ +
+ "; + $header_rows = count($header); + $navigationOutput = getTableHeaderSimpleNavigation($navigation_array, $url_string,"Calendar","index"); + + + if($navigationOutput != '') + { + $list_view .= ""; + } + $list_view .= ""; + for($i=0;$i<$header_rows;$i++) + { + $list_view .=""; + } + $list_view .=""; + $rows = count($todo_list); + if($rows != 0) + { + for($i=0;$i$entry) + { + $list_view .=""; + } + $list_view .=""; + } + } + else + { + $list_view .=""; + } + $list_view .="
"; + $list_view .= "".$navigationOutput."
".$header[$i]."
".$entry."
"; + $list_view .="
+ + + + + + "; + //checking permission for Create/Edit Operation + if(isPermitted("Calendar","EditView") == "yes") + { + $list_view .=""; + } + else + { + $list_view .=""; + } + + $list_view .=" +
+ ".$app_strings['LBL_NO']." ".$app_strings['Todos']." ".$app_strings['LBL_FOUND']." !
".$app_strings['LBL_YOU_CAN_CREATE']." ".$app_strings['LBL_A']." ".$app_strings['Todo']." ".$app_strings['LBL_NOW'].". ".$app_strings['LBL_CLICK_THE_LINK']." :
+   -".$app_strings['LBL_CREATE']." ".$app_strings['LBL_A']." ".$app_strings['Todo']." +
".$app_strings['LBL_YOU_ARE_NOT_ALLOWED_TO_CREATE']." ".$app_strings['LBL_A']." ".$app_strings['Todo']."
+
"; + $list_view .="

"; + $cal_log->debug("Exiting constructTodoListView() method..."); + return $list_view; +} + +/** + * Function returns the list of privileges and permissions of the events that the current user can view the details of. + * return string - query that is used as secondary parameter to fetch the events that the user can view and the schedule of the users + */ +function getCalendarViewSecurityParameter() +{ + global $current_user; + require('user_privileges/user_privileges_'.$current_user->id.'.php'); + require('user_privileges/sharing_privileges_'.$current_user->id.'.php'); + + require_once('modules/Calendar/CalendarCommon.php'); + $shared_ids = getSharedCalendarId($current_user->id); + if(isset($shared_ids) && $shared_ids != '') + $condition = " or (vtiger_crmentity.smownerid in($shared_ids)) or (vtiger_crmentity.smownerid NOT LIKE ($current_user->id))";// and vtiger_activity.visibility = 'Public')"; + else + $condition = "or (vtiger_crmentity.smownerid NOT LIKE ($current_user->id))"; + $sec_query .= " and (vtiger_crmentity.smownerid in($current_user->id) $condition or vtiger_crmentity.smownerid in(select vtiger_user2role.userid 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 '".$current_user_parent_role_seq."::%')"; + + if(sizeof($current_user_groups) > 0) + { + $sec_query .= " or (vtiger_groups.groupid in (". implode(",", $current_user_groups) ."))"; + } + $sec_query .= ")"; + return $sec_query; +} +?> diff --git a/oss/vtiger/trunk/modules/Calendar/calendar_share.php b/oss/vtiger/trunk/modules/Calendar/calendar_share.php new file mode 100644 index 00000000..f6cc7d37 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/calendar_share.php @@ -0,0 +1,169 @@ +id); + $shareduser_ids = getSharedUserId($current_user->id); +?> + + + + + +
+ +
+
+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +
+
+ start_hour != ''){?> checked onClick="enableCalstarttime();">  +
+ hour_format == '24'){?> checked value="24">  +
+
+

+ +
+ + + + +
+ + + + + + + + + + + + + +
+
    +
  • +
  • +
+
 
+ + + +
+ +
+ + + + + +
+ + +
+ +
+
+
+ + + + +
+    + +
+
+ diff --git a/oss/vtiger/trunk/modules/Calendar/disable_sharing.php b/oss/vtiger/trunk/modules/Calendar/disable_sharing.php new file mode 100644 index 00000000..6b73acb2 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/disable_sharing.php @@ -0,0 +1,22 @@ +pquery($sql, array($id)); +} +header("Location:index.php?module=".$returnmodule."&action=".$returnaction); +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/header.php b/oss/vtiger/trunk/modules/Calendar/header.php new file mode 100644 index 00000000..dbe3e5e2 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/header.php @@ -0,0 +1,120 @@ + + + + + '.$app_strings[$category].' > '.$app_strings["Calendar"].' + + + + + + + +
+ + + + + +
+
+ +   + + + + + '; + + + if($CALENDAR_DISPLAY == 'true') + $html_string .= ' '; + if($WORLD_CLOCK_DISPLAY == 'true') + $html_string .= ' '; + if($CALCULATOR_DISPLAY == 'true') + $html_string .= ' '; + if($CHAT_DISPLAY == 'true') + $html_string .= ' '; + + $html_string .= ' + + +
'.$app_strings['LBL_CALENDAR_ALT'].''.$app_strings['LBL_CLOCK_ALT'].''.$app_strings['LBL_CALCULATOR_ALT'].''.$app_strings['LBL_CHAT_ALT'].''.$app_strings['LBL_LAST_VIEWED'].'
+ +   + + + + + + + +
+ +   + + + + '; + if((isPermitted('Settings','index') == 'yes')) + $html_string .= ''; + $html_string .= ' +
'.$app_strings['LBL_ALL_MENU_ALT'].''.$app_strings['LBL_SETTINGS'].'
+ + + + + + + + + + +
+ + +
+ + + + + +
+ + + + + + + + +
 '.$app_strings["Calendar"].' '.$mod_strings["LBL_ALL_EVENTS_TODOS"].' 
+
+ + +
+ + + +
+ '; + echo $html_string; +?> diff --git a/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_components.php b/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_components.php new file mode 100644 index 00000000..3e6e7fcd --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_components.php @@ -0,0 +1,628 @@ +construct(); + } + + function construct() { + // Initialize the components array + if(empty($this->components)) { + $this->components = array(); + foreach($this->valid_components as $name) { + $this->components[$name] = array(); + } + } + } + + function get_name() { + return $this->name; + } + + function add_property($name, $value = NULL, $parameters = NULL) { + + // Uppercase first of all + $name = strtoupper($name); + // Are we trying to add a valid property? + $xname = false; + if(!isset($this->valid_properties[$name])) { + // If not, is it an x-name as per RFC 2445? + if(!rfc2445_is_xname($name)) { + return false; + } + // Since this is an xname, all components are supposed to allow this property + $xname = true; + } + + // Create a property object of the correct class + if($xname) { + $property = new iCalendar_property_x; + $property->set_name($name); + } + else { + $classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $name)); + $property = new $classname; + } + // If $value is NULL, then this property must define a default value. + if($value === NULL) { + $value = $property->default_value(); + if($value === NULL) { + return false; + } + } + + // Set this property's parent component to ourselves, because some + // properties behave differently according to what component they apply to. + $property->set_parent_component($this->name); + + // Set parameters before value; this helps with some properties which + // accept a VALUE parameter, and thus change their default value type. + + // The parameters must be valid according to property specifications + if(!empty($parameters)) { + foreach($parameters as $paramname => $paramvalue) { + if(!$property->set_parameter($paramname, $paramvalue)) { + return false; + } + } + + // Some parameters interact among themselves (e.g. ENCODING and VALUE) + // so make sure that after the dust settles, these invariants hold true + if(!$property->invariant_holds()) { + return false; + } + } + + // $value MUST be valid according to the property data type + if(!$property->set_value($value)) { + return false; + } + + // If this property is restricted to only once, blindly overwrite value + if(!$xname && $this->valid_properties[$name] & RFC2445_ONCE) { + $this->properties[$name] = array($property); + } + + // Otherwise add it to the instance array for this property + else { + $this->properties[$name][] = $property; + } + + // Finally: after all these, does the component invariant hold? + if(!$this->invariant_holds()) { + // If not, completely undo the property addition + array_pop($this->properties[$name]); + if(empty($this->properties[$name])) { + unset($this->properties[$name]); + } + return false; + } + + return true; + + } + + function add_component($component) { + + // With the detailed interface, you can add only components with this function + if(!is_object($component) || !is_subclass_of($component, 'iCalendar_component')) { + return false; + } + + $name = $component->get_name(); + + // Only valid components as specified by this component are allowed + if(!in_array($name, $this->valid_components)) { + return false; + } + + // Add it + $this->components[$name][] = $component; + + return true; + } + + function get_property_list($name) { + } + + function invariant_holds() { + return true; + } + + function is_valid() { + // If we have any child components, check that they are all valid + if(!empty($this->components)) { + foreach($this->components as $component => $instances) { + foreach($instances as $number => $instance) { + if(!$instance->is_valid()) { + return false; + } + } + } + } + // Finally, check the valid property list for any mandatory properties + // that have not been set and do not have a default value + foreach($this->valid_properties as $property => $propdata) { + if(($propdata & RFC2445_REQUIRED) && empty($this->properties[$property])) { + $classname = 'iCalendar_property_'.strtolower(str_replace('-', '_', $property)); + $object = new $classname; + if($object->default_value() === NULL) { + return false; + } + unset($object); + } + } + + return true; + } + + function serialize() { + // Check for validity of the object + if(!$this->is_valid()) { + return false; + } + + // Maybe the object is valid, but there are some required properties that + // have not been given explicit values. In that case, set them to defaults. + foreach($this->valid_properties as $property => $propdata) { + if(($propdata & RFC2445_REQUIRED) && empty($this->properties[$property])) { + $this->add_property($property); + } + } + + // Start tag + $string = rfc2445_fold('BEGIN:'.$this->name) . RFC2445_CRLF; + // List of properties + if(!empty($this->properties)) { + foreach($this->properties as $name => $properties) { + foreach($properties as $property) { + $string .= $property->serialize(); + } + } + } + // List of components + if(!empty($this->components)) { + foreach($this->components as $name => $components) { + foreach($components as $component) { + $string .= $component->serialize(); + } + } + } + + // End tag + $string .= rfc2445_fold('END:'.$this->name) . RFC2445_CRLF; + + return $string; + } + + function assign_values($activity) { + foreach($this->mapping_arr as $key=>$components){ + if(!is_array($components['component']) && empty($components['function'])){ + $this->add_property($key,$activity[$components['component']]); + } else if(is_array($components['component']) && empty($components['function'])){ + $component = ''; + foreach($components['component'] as $comp){ + if(!empty($component)) $component .= ','; + $component .= $activity[$comp]; + } + $this->add_property($key,$component); + } else if(!empty($components['function'])){ + $this->$components['function']($activity); + } + } + return true; + } + + function generateArray($ical_activity){ + global $current_user; + $activity = array(); + $activitytype = $ical_activity['TYPE']; + if($activitytype=='VEVENT'){ + $modtype = 'Events'; + } else { + $modtype = 'Calendar'; + } + foreach($this->mapping_arr as $key=>$comp){ + $type = $comp['type']; + $component = $comp['component']; + if(!is_array($component)){ + if($type!='user'){ + if(isset($this->field_mapping_arr[$component])){ + if(getFieldVisibilityPermission($modtype,$current_user->id,$this->field_mapping_arr[$component])=='0') + $activity[$this->field_mapping_arr[$component]] = $ical_activity[$key]; + else + $activity[$this->field_mapping_arr[$component]] = ''; + } else { + if(getFieldVisibilityPermission($modtype,$current_user->id,$component)=='0') + $activity[$component] = $ical_activity[$key]; + else + $activity[$component] = ''; + } + } + } else { + $temp = $ical_activity[$key]; + $count = 0; + if($type == 'string'){ + $values = explode('\\,',$temp); + } else if($type == 'datetime'){ + $values = $this->strtodatetime($temp); + } + foreach($component as $index){ + if(!isset($activity[$index])){ + if(isset($this->field_mapping_arr[$index])){ + if(getFieldVisibilityPermission($modtype,$current_user->id,$this->field_mapping_arr[$index])=='0') + $activity[$this->field_mapping_arr[$index]] = $values[$count]; + else + $activity[$this->field_mapping_arr[$index]] = ''; + } else { + if(getFieldVisibilityPermission($modtype,$current_user->id,$index)=='0') + $activity[$index] = $values[$count]; + else + $activity[$index] = ''; + } + } + $count++; + } + unset($values); + } + } + if($activitytype=='VEVENT'){ + $activity['activitytype'] = 'Meeting'; + if(!empty($ical_activity['VALARM'])){ + $temp = str_replace("PT",'',$ical_activity['VALARM']['TRIGGER']); + $duration_type = $temp[strlen($temp)-1]; + $duration = intval($temp); + if($duration_type=='H'){ + $reminder_time = $duration*60; + } else if($duration_type=='M'){ + $reminder_time = $duration; + } + $activity['reminder_time'] = $reminder_time; + } + } else { + $activity['activitytype'] = 'Task'; + } + return $activity; + } + + function strtodatetime($date){ + $date = preg_replace('/[A-Za-z_]*/', '', $date); + $year = substr($date,0,4); + $month = substr($date,4,2); + $day = substr($date,6,2); + $hours = substr($date,8,2); + $minutes = substr($date,10,2); + $seconds = substr($date,12,2); + $datetime[] = $year."-".$month."-".$day; + $datetime[] = $hours.":".$minutes.":".$seconds; + return $datetime; + } +} + +class iCalendar extends iCalendar_component { + var $name = 'VCALENDAR'; + + function construct() { + $this->valid_properties = array( + 'CALSCALE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'METHOD' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'PRODID' => RFC2445_REQUIRED | RFC2445_ONCE, + 'VERSION' => RFC2445_REQUIRED | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + + $this->valid_components = array( + 'VEVENT', 'VTODO', 'VTIMEZONE' + // TODO: add support for the other component types + //, 'VJOURNAL', 'VFREEBUSY', 'VALARM' + ); + parent::construct(); + } + +} + +class iCalendar_event extends iCalendar_component { + + var $name = 'VEVENT'; + var $properties; + var $mapping_arr = array( + 'CLASS' => array('component'=>'visibility','type'=>'string'), + 'DESCRIPTION' => array('component'=>'description','type'=>'string'), + 'DTSTART' => array('component'=>array('date_start','time_start'),'function'=>'iCalendar_event_dtstart','type'=>'datetime'), + 'DTEND' => array('component'=>array('due_date','time_end'),'function'=>'iCalendar_event_dtend','type'=>'datetime'), + 'DTSTAMP' => array('component'=>array('date_start','time_start'),'function'=>'iCalendar_event_dtstamp','type'=>'datetime'), + 'LOCATION' => array('component'=>'location','type'=>'string'), + 'STATUS' => array('component'=>'eventstatus','type'=>'string'), + 'SUMMARY' => array('component'=>'subject','type'=>'string'), + 'PRIORITY' => array('component'=>'priority','type'=>'string'), + 'ATTENDEE' => array('component'=>'activityid','function'=>'iCalendar_event_attendee','type'=>'user'), + 'RESOURCES' => array('component'=>array('location','eventstatus'),'type'=>'string'), + ); + var $field_mapping_arr = array( + 'priority'=>'taskpriority' + ); + + function construct() { + + $this->valid_components = array('VALARM'); + + $this->valid_properties = array( + 'CLASS' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'CREATED' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DESCRIPTION' => RFC2445_OPTIONAL | RFC2445_ONCE, + // Standard ambiguous here: in 4.6.1 it says that DTSTAMP in optional, + // while in 4.8.7.2 it says it's REQUIRED. Go with REQUIRED. + 'DTSTAMP' => RFC2445_REQUIRED | RFC2445_ONCE, + // Standard ambiguous here: in 4.6.1 it says that DTSTART in optional, + // while in 4.8.2.4 it says it's REQUIRED. Go with REQUIRED. + 'DTSTART' => RFC2445_REQUIRED | RFC2445_ONCE, + 'GEO' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LAST-MODIFIED' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LOCATION' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'ORGANIZER' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'PRIORITY' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'SEQUENCE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'STATUS' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'SUMMARY' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'TRANSP' => RFC2445_OPTIONAL | RFC2445_ONCE, + // Standard ambiguous here: in 4.6.1 it says that UID in optional, + // while in 4.8.4.7 it says it's REQUIRED. Go with REQUIRED. + 'UID' => RFC2445_REQUIRED | RFC2445_ONCE, + 'URL' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'RECURRENCE-ID' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DTEND' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DURATION' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'ATTACH' => RFC2445_OPTIONAL, + 'ATTENDEE' => RFC2445_OPTIONAL, + 'CATEGORIES' => RFC2445_OPTIONAL, + 'COMMENT' => RFC2445_OPTIONAL, + 'CONTACT' => RFC2445_OPTIONAL, + 'EXDATE' => RFC2445_OPTIONAL, + 'EXRULE' => RFC2445_OPTIONAL, + 'REQUEST-STATUS' => RFC2445_OPTIONAL, + 'RELATED-TO' => RFC2445_OPTIONAL, + 'RESOURCES' => RFC2445_OPTIONAL, + 'RDATE' => RFC2445_OPTIONAL, + 'RRULE' => RFC2445_OPTIONAL, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + + parent::construct(); + } + + function invariant_holds() { + // DTEND and DURATION must not appear together + if(isset($this->properties['DTEND']) && isset($this->properties['DURATION'])) { + return false; + } + + + if(isset($this->properties['DTEND']) && isset($this->properties['DTSTART'])) { + // DTEND must be later than DTSTART + // The standard is not clear on how to hande different value types though + // TODO: handle this correctly even if the value types are different + if($this->properties['DTEND'][0]->value <= $this->properties['DTSTART'][0]->value) { + return false; + } + + // DTEND and DTSTART must have the same value type + if($this->properties['DTEND'][0]->val_type != $this->properties['DTSTART'][0]->val_type) { + return false; + } + + } + return true; + } + + function iCalendar_event_dtstamp($activity){ + $components = gmdate('Ymd', strtotime($activity['date_start']." ".$activity['time_start']))."T".gmdate('His', strtotime($activity['date_start']." ".$activity['time_start']))."Z"; + $this->add_property("DTSTAMP",$components); + return true; + } + + function iCalendar_event_dtstart($activity){ + $time = str_replace(':','',$activity['time_start']); + if(strlen($time)<6){ + while((6-strlen($time)) > 0 ){ + $time .= '0'; + } + } + $components = str_replace('-', '', $activity['date_start']).'T'. $time . 'Z'; + $this->add_property("DTSTART",$components); + return true; + } + + function iCalendar_event_dtend($activity){ + $time = str_replace(':','',$activity['time_end']); + if(strlen($time)<6){ + while((6-strlen($time)) > 0 ){ + $time .= '0'; + } + } + $components = str_replace('-', '', $activity['due_date']).'T'. $time . 'Z'; + $this->add_property("DTEND",$components); + return true; + } + + function iCalendar_event_attendee($activity){ + global $adb; + $users_res = $adb->pquery("SELECT inviteeid FROM vtiger_invitees WHERE activityid=?", array($activity['id'])); + if($adb->num_rows($users_res)>0){ + for($i=0;$i<$adb->num_rows($users_res);$i++){ + $inviteeid = $adb->query_result($users_res,$i,'inviteeid'); + $username = getUserFullName($inviteeid); + $user_email = getUserEmail($inviteeid); + $attendee = 'mailto:'.$user_email; + $this->add_property('ATTENDEE',$attendee); + } + } + return true; + } + +} + +class iCalendar_todo extends iCalendar_component { + var $name = 'VTODO'; + var $properties; + var $mapping_arr = array( + 'DESCRIPTION' => array('component'=>'description','type'=>'string'), + 'DTSTAMP' => array('component'=>array('date_start','time_start'),'function'=>'iCalendar_event_dtstamp','type'=>'datetime'), + 'DTSTART' => array('component'=>array('date_start','time_start'),'function'=>'iCalendar_event_dtstart','type'=>'datetime'), + 'DUE' => array('component'=>array('due_date'),'function'=>'iCalendar_event_dtend','type'=>'datetime'), + 'STATUS' => array('component'=>'status','type'=>'string'), + 'SUMMARY' => array('component'=>'subject','type'=>'string'), + 'PRIORITY' => array('component'=>'priority','type'=>'string'), + 'RESOURCES' => array('component'=>array('status'),'type'=>'string'), + ); + var $field_mapping_arr = array( + 'status'=>'taskstatus', + 'priority'=>'taskpriority' + ); + + function construct() { + + $this->valid_components = array(); + $this->valid_properties = array( + 'CLASS' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'COMPLETED' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'CREATED' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DESCRIPTION' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DTSTAMP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DTSTART' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'GEO' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LAST-MODIFIED' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LOCATION' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'ORGANIZER' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'PERCENT' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'PRIORITY' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'RECURID' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'SEQUENCE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'STATUS' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'SUMMARY' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'UID' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'URL' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DUE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DURATION' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'ATTACH' => RFC2445_OPTIONAL, + 'ATTENDEE' => RFC2445_OPTIONAL, + 'CATEGORIES' => RFC2445_OPTIONAL, + 'COMMENT' => RFC2445_OPTIONAL, + 'CONTACT' => RFC2445_OPTIONAL, + 'EXDATE' => RFC2445_OPTIONAL, + 'EXRULE' => RFC2445_OPTIONAL, + 'RSTATUS' => RFC2445_OPTIONAL, + 'RELATED' => RFC2445_OPTIONAL, + 'RESOURCES' => RFC2445_OPTIONAL, + 'RDATE' => RFC2445_OPTIONAL, + 'RRULE' => RFC2445_OPTIONAL, + 'XPROP' => RFC2445_OPTIONAL + ); + + parent::construct(); + // TODO: + // either 'due' or 'duration' may appear in a 'eventprop', but 'due' + // and 'duration' MUST NOT occur in the same 'eventprop' + } + function iCalendar_event_dtstamp($activity){ + $components = gmdate('Ymd', strtotime($activity['date_start']." ".$activity['time_start']))."T".gmdate('His', strtotime($activity['date_start']." ".$activity['time_start']))."Z"; + $this->add_property("DTSTAMP",$components); + return true; + } + + function iCalendar_event_dtstart($activity){ + $time = str_replace(':','',$activity['time_start']); + if(strlen($time)<6){ + while((6-strlen($time)) > 0 ){ + $time .= '0'; + } + } + $components = str_replace('-', '', $activity['date_start']).'T'. $time . 'Z'; + $this->add_property("DTSTART",$components); + return true; + } + + function iCalendar_event_dtend($activity){ + $components = str_replace('-', '', $activity['due_date']).'T000000Z'; + $this->add_property("DUE",$components); + return true; + } +} + +class iCalendar_journal extends iCalendar_component { + // TODO: implement +} + +class iCalendar_freebusy extends iCalendar_component { + // TODO: implement +} + +class iCalendar_alarm extends iCalendar_component { + var $name='VALARM'; + var $properties; + var $mapping_arr = array( + 'TRIGGER' => array('component'=>'reminder_time', 'function'=>'iCalendar_event_trigger'), + ); + + function construct() { + + $this->valid_components = array(); + $this->valid_properties = array( + 'TRIGGER' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DESCRIPTION' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'ACTION' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'X-WR-ALARMUID' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + + parent::construct(); + } + + function iCalendar_event_trigger($activity){ + $reminder_time = $activity['reminder_time']; + if($reminder_time>60){ + $reminder_time = round($reminder_time/60); + $reminder = $reminder_time.'H'; + }else { + $reminder = $reminder_time.'M'; + } + $this->add_property('ACTION', 'DISPLAY'); + $this->add_property('TRIGGER', 'PT'.$reminder); + $this->add_property('DESCRIPTION', 'Reminder'); + return true; + } +} + +class iCalendar_timezone extends iCalendar_component { + var $name = 'VTIMEZONE'; + var $properties; + + function construct() { + $this->valid_components = array(); + $this->valid_properties = array( + 'TZID' => RFC2445_REQUIRED | RFC2445_ONCE, + 'LAST-MODIFIED' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'TZURL' => RFC2445_OPTIONAL | RFC2445_ONCE, + // TODO: the next two are components of their own! + 'STANDARDC' => RFC2445_OPTIONAL, + 'DAYLIGHTC' => RFC2445_OPTIONAL, + 'TZOFFSETFROM' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'TZOFFSETTO' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'X-PROP' => RFC2445_OPTIONAL + ); + + parent::construct(); + } + +} + +// REMINDER: DTEND must be later than DTSTART for all components which support both +// REMINDER: DUE must be later than DTSTART for all components which support both + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_parameters.php b/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_parameters.php new file mode 100644 index 00000000..1b029c9c --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_parameters.php @@ -0,0 +1,227 @@ + array('PLAIN', 'RICHTEXT', 'ENRICHED', 'TAB-SEPARATED-VALUES', 'HTML', 'SGML', + 'VND.LATEX-Z', 'VND.FMI.FLEXSTOR'), + 'MULTIPART' => array('MIXED', 'ALTERNATIVE', 'DIGEST', 'PARALLEL', 'APPLEDOUBLE', 'HEADER-SET', + 'FORM-DATA', 'RELATED', 'REPORT', 'VOICE-MESSAGE', 'SIGNED', 'ENCRYPTED', + 'BYTERANGES'), + 'MESSAGE' => array('RFC822', 'PARTIAL', 'EXTERNAL-BODY', 'NEWS', 'HTTP'), + 'APPLICATION' => array('OCTET-STREAM', 'POSTSCRIPT', 'ODA', 'ATOMICMAIL', 'ANDREW-INSET', 'SLATE', + 'WITA', 'DEC-DX', 'DCA-RFT', 'ACTIVEMESSAGE', 'RTF', 'APPLEFILE', + 'MAC-BINHEX40', 'NEWS-MESSAGE-ID', 'NEWS-TRANSMISSION', 'WORDPERFECT5.1', + 'PDF', 'ZIP', 'MACWRITEII', 'MSWORD', 'REMOTE-PRINTING', 'MATHEMATICA', + 'CYBERCASH', 'COMMONGROUND', 'IGES', 'RISCOS', 'ESHOP', 'X400-BP', 'SGML', + 'CALS-1840', 'PGP-ENCRYPTED', 'PGP-SIGNATURE', 'PGP-KEYS', 'VND.FRAMEMAKER', + 'VND.MIF', 'VND.MS-EXCEL', 'VND.MS-POWERPOINT', 'VND.MS-PROJECT', + 'VND.MS-WORKS', 'VND.MS-TNEF', 'VND.SVD', 'VND.MUSIC-NIFF', 'VND.MS-ARTGALRY', + 'VND.TRUEDOC', 'VND.KOAN', 'VND.STREET-STREAM', 'VND.FDF', + 'SET-PAYMENT-INITIATION', 'SET-PAYMENT', 'SET-REGISTRATION-INITIATION', + 'SET-REGISTRATION', 'VND.SEEMAIL', 'VND.BUSINESSOBJECTS', + 'VND.MERIDIAN-SLINGSHOT', 'VND.XARA', 'SGML-OPEN-CATALOG', 'VND.RAPID', + 'VND.ENLIVEN', 'VND.JAPANNET-REGISTRATION-WAKEUP', + 'VND.JAPANNET-VERIFICATION-WAKEUP', 'VND.JAPANNET-PAYMENT-WAKEUP', + 'VND.JAPANNET-DIRECTORY-SERVICE', 'VND.INTERTRUST.DIGIBOX', 'VND.INTERTRUST.NNCP'), + 'IMAGE' => array('JPEG', 'GIF', 'IEF', 'G3FAX', 'TIFF', 'CGM', 'NAPLPS', 'VND.DWG', 'VND.SVF', + 'VND.DXF', 'PNG', 'VND.FPX', 'VND.NET-FPX'), + 'AUDIO' => array('BASIC', '32KADPCM', 'VND.QCELP'), + 'VIDEO' => array('MPEG', 'QUICKTIME', 'VND.VIVO', 'VND.MOTOROLA.VIDEO', 'VND.MOTOROLA.VIDEOP') + ); + $value = strtoupper($value); + if(rfc2445_is_xname($value)) { + return true; + } + @list($type, $subtype) = explode('/', $value); + if(empty($type) || empty($subtype)) { + return false; + } + if(!isset($fmttypes[$type]) || !in_array($subtype, $fmttypes[$type])) { + return false; + } + return true; + break; + + case 'LANGUAGE': + $value = strtoupper($value); + $parts = explode('-', $value); + foreach($parts as $part) { + if(empty($part)) { + return false; + } + if(strspn($part, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') != strlen($part)) { + return false; + } + } + return true; + break; + + case 'PARTSTAT': + $value = strtoupper($value); + switch($parent_property->parent_component) { + case 'VEVENT': + return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || $value == 'TENTATIVE' + || $value == 'DELEGATED' || rfc2445_is_xname($value)); + break; + case 'VTODO': + return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || $value == 'TENTATIVE' + || $value == 'DELEGATED' || $value == 'COMPLETED' || $value == 'IN-PROCESS' || rfc2445_is_xname($value)); + break; + case 'VJOURNAL': + return ($value == 'NEEDS-ACTION' || $value == 'ACCEPTED' || $value == 'DECLINED' || rfc2445_is_xname($value)); + break; + } + return false; + break; + + case 'RANGE': + $value = strtoupper($value); + return ($value == 'THISANDPRIOR' || $value == 'THISANDFUTURE'); + break; + + case 'RELATED': + $value = strtoupper($value); + return ($value == 'START' || $value == 'END'); + break; + + case 'RELTYPE': + $value = strtoupper($value); + return ($value == 'PARENT' || $value == 'CHILD' || $value == 'SIBLING' || rfc2445_is_xname($value)); + break; + + case 'ROLE': + $value = strtoupper($value); + return ($value == 'CHAIR' || $value == 'REQ-PARTICIPANT' || $value == 'OPT-PARTICIPANT' || $value == 'NON-PARTICIPANT' || rfc2445_is_xname($value)); + break; + + case 'RSVP': + $value = strtoupper($value); + return ($value == 'TRUE' || $value == 'FALSE'); + break; + + case 'TZID': + if(empty($value)) { + return false; + } + return (strcspn($value, '";:,') == strlen($value)); + break; + + case 'VALUE': + $value = strtoupper($value); + return ($value == 'BINARY' || $value == 'BOOLEAN' || $value == 'CAL-ADDRESS' || $value == 'DATE' || + $value == 'DATE-TIME' || $value == 'DURATION' || $value == 'FLOAT' || $value == 'INTEGER' || + $value == 'PERIOD' || $value == 'RECUR' || $value == 'TEXT' || $value == 'TIME' || + $value == 'URI' || $value == 'UTC-OFFSET' || rfc2445_is_xname($value)); + break; + } + } + + function do_value_formatting($parameter, $value) { + switch($parameter) { + // Parameters of type CAL-ADDRESS or URI MUST be double-quoted + case 'ALTREP': + case 'DIR': + case 'DELEGATED-FROM': + case 'DELEGATED-TO': + case 'MEMBER': + case 'SENT-BY': + return '"'.$value.'"'; + break; + + // Textual parameter types must be double quoted if they contain COLON, SEMICOLON + // or COMMA. Quoting always sounds easier and standards-conformant though. + case 'CN': + return '"'.$value.'"'; + break; + + // Parameters with enumerated legal values, just make them all caps + case 'CUTYPE': + case 'ENCODING': + case 'FBTYPE': + case 'FMTTYPE': + case 'LANGUAGE': + case 'PARTSTAT': + case 'RANGE': + case 'RELATED': + case 'RELTYPE': + case 'ROLE': + case 'RSVP': + case 'VALUE': + return strtoupper($value); + break; + + // Parameters we shouldn't be messing with + case 'TZID': + return $value; + break; + } + } + + function undo_value_formatting($parameter, $value) { + } + +} + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_properties.php b/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_properties.php new file mode 100644 index 00000000..2c373e0a --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_properties.php @@ -0,0 +1,1367 @@ +construct(); + } + + function construct() { + $this->parameters = array(); + } + + // If some property needs extra care with its parameters, override this + // IMPORTANT: the parameter name MUST BE CAPITALIZED! + function is_valid_parameter($parameter, $value) { + + if(is_array($value)) { + if(!iCalendar_parameter::multiple_values_allowed($parameter)) { + return false; + } + foreach($value as $item) { + if(!iCalendar_parameter::is_valid_value($this, $parameter, $item)) { + return false; + } + } + return true; + } + + return iCalendar_parameter::is_valid_value($this, $parameter, $value); + } + + function invariant_holds() { + return true; + } + + // If some property is very picky about its values, it should do the work itself + // Only data type validation is done here + function is_valid_value($value) { + if(is_array($value)) { + if(!$this->val_multi) { + return false; + } + else { + foreach($value as $oneval) { + if(!rfc2445_is_valid_value($oneval, $this->val_type)) { + return false; + } + } + } + return true; + } + return rfc2445_is_valid_value($value, $this->val_type); + } + + function default_value() { + return $this->val_default; + } + + function set_parent_component($componentname) { + if(class_exists('iCalendar_'.strtolower(substr($componentname, 1)))) { + $this->parent_component = strtoupper($componentname); + return true; + } + + return false; + } + + function set_value($value) { + if($this->is_valid_value($value)) { + // This transparently formats any value type according to the iCalendar specs + if(is_array($value)) { + foreach($value as $key => $item) { + $value[$key] = rfc2445_do_value_formatting($item, $this->val_type); + } + $this->value = implode(',', $value); + } + else { + $this->value = rfc2445_do_value_formatting($value, $this->val_type); + } + + return true; + } + return false; + } + + function get_value() { + // First of all, assume that we have multiple values + $valarray = explode('\\,', $this->value); + + // Undo transparent formatting + $replace_function = create_function('$a', 'return rfc2445_undo_value_formatting($a, '.$this->val_type.');'); + $valarray = array_map($replace_function, $valarray); + + // Now, if this property cannot have multiple values, don't return as an array + if(!$this->val_multi) { + return $valarray[0]; + } + + // Otherwise return an array even if it has one element, for uniformity + return $valarray; + + } + + function set_parameter($name, $value) { + + // Uppercase + $name = strtoupper($name); + + // Are we trying to add a valid parameter? + $xname = false; + if(!isset($this->valid_parameters[$name])) { + // If not, is it an x-name as per RFC 2445? + if(!rfc2445_is_xname($name)) { + return false; + } + // No more checks -- all components are supposed to allow x-name parameters + $xname = true; + } + + if(!$this->is_valid_parameter($name, $value)) { + return false; + } + + if(is_array($value)) { + foreach($value as $key => $element) { + $value[$key] = iCalendar_parameter::do_value_formatting($name, $element); + } + } + else { + $value = iCalendar_parameter::do_value_formatting($name, $value); + } + + $this->parameters[$name] = $value; + + // Special case: if we just changed the VALUE parameter, reflect this + // in the object's status so that it only accepts correct type values + if($name == 'VALUE') { + // TODO: what if this invalidates an already-set value? + $this->val_type = constant('RFC2445_TYPE_'.str_replace('-', '_', $value)); + } + + return true; + + } + + function get_parameter($name) { + + // Uppercase + $name = strtoupper($name); + + if(isset($this->parameters[$name])) { + // If there are any double quotes in the value, invisibly strip them + if(is_array($this->parameters[$name])) { + foreach($this->parameters[$name] as $key => $value) { + if(substr($value, 0, 1) == '"') { + $this->parameters[$name][$key] = substr($value, 1, strlen($value) - 2); + } + } + return $this->parameters[$name]; + } + + else { + if(substr($this->parameters[$name], 0, 1) == '"') { + return substr($this->parameters[$name], 1, strlen($this->parameters[$name]) - 2); + } + } + } + + return NULL; + } + + function serialize() { + $string = $this->name; + + if(!empty($this->parameters)) { + foreach($this->parameters as $name => $value) { + $string .= ';'.$name.'='; + if(is_array($value)) { + $string .= implode(',', $value); + } + else { + $string .= $value; + } + } + } + + $string .= ':'.$this->value; + + return rfc2445_fold($string) . RFC2445_CRLF; + } +} + +// 4.7 Calendar Properties +// ----------------------- + +class iCalendar_property_calscale extends iCalendar_property { + + var $name = 'CALSCALE'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + // This is case-sensitive + return ($value === 'GREGORIAN'); + } +} + +class iCalendar_property_method extends iCalendar_property { + + var $name = 'METHOD'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + // This is case-sensitive + // Methods from RFC 2446 + $methods == array('PUBLISH', 'REQUEST', 'REPLY', 'ADD', 'CANCEL', 'REFRESH', 'COUNTER', 'DECLINECOUNTER'); + return in_array($value, $methods); + } +} + +class iCalendar_property_prodid extends iCalendar_property { + + var $name = 'PRODID'; + var $val_type = RFC2445_TYPE_TEXT; + var $val_default = NULL; + + function construct() { + $this->val_default = '-//John Papaioannou/NONSGML Bennu '._BENNU_VERSION.'//EN'; + + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_version extends iCalendar_property { + + var $name = 'VERSION'; + var $val_type = RFC2445_TYPE_TEXT; + var $val_default = '2.0'; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + return($value === '2.0' || $value === 2.0); + } + +} + +// 4.8.1 Descriptive Component Properties +// -------------------------------------- + +class iCalendar_property_attach extends iCalendar_property { + + var $name = 'ATTACH'; + var $val_type = RFC2445_TYPE_URI; + + function construct() { + $this->valid_parameters = array( + 'FMTTYPE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'ENCODING' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'VALUE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function invariant_holds() { + if(isset($this->parameters['ENCODING']) && !isset($this->parameters['VALUE'])) { + return false; + } + if(isset($this->parameters['VALUE']) && !isset($this->parameters['ENCODING'])) { + return false; + } + + return true; + } + + function is_valid_parameter($parameter, $value) { + + $parameter = strtoupper($parameter); + + if(!parent::is_valid_parameter($parameter, $value)) { + return false; + } + + if($parameter === 'ENCODING' && strtoupper($value) != 'BASE64') { + return false; + } + + if($parameter === 'VALUE' && strtoupper($value) != 'BINARY') { + return false; + } + + return true; + } +} + +class iCalendar_property_categories extends iCalendar_property { + + var $name = 'CATEGORIES'; + var $val_type = RFC2445_TYPE_TEXT; + var $val_multi = true; + + function construct() { + $this->valid_parameters = array( + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_class extends iCalendar_property { + + var $name = 'CLASS'; + var $val_type = RFC2445_TYPE_TEXT; + var $val_default = 'PUBLIC'; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + function is_valid_value($value) { + $value = strtoupper($value); + // If this is not an xname, it is case-sensitive + return ($value === 'PUBLIC' || $value === 'PRIVATE' || $value === 'CONFIDENTIAL' || rfc2445_is_xname(strtoupper($value))); + } +} + +class iCalendar_property_comment extends iCalendar_property { + + var $name = 'COMMENT'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + 'ALTREP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_description extends iCalendar_property { + + var $name = 'DESCRIPTION'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + 'ALTREP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_geo extends iCalendar_property { + + var $name = 'GEO'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + 'ALTREP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + // This MUST be two floats separated by a semicolon + if(!is_string($value)) { + return false; + } + + $floats = explode(';', $value); + if(count($floats) != 2) { + return false; + } + + return rfc2445_is_valid_value($floats[0], RFC2445_TYPE_FLOAT) && rfc2445_is_valid_value($floats[1], RFC2445_TYPE_FLOAT); + } + + function set_value($value) { + // Must override this, otherwise the semicolon separating + // the two floats would get auto-quoted, which is illegal + if($this->is_valid_value($value)) { + $this->value = $value; + return true; + } + + return false; + } + +} + +class iCalendar_property_location extends iCalendar_property { + + var $name = 'LOCATION'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + 'ALTREP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_percent_complete extends iCalendar_property { + + var $name = 'PERCENT-COMPLETE'; + var $val_type = RFC2445_TYPE_INTEGER; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + // Only integers between 0 and 100 inclusive allowed + if(!parent::is_valid_value($value)) { + return false; + } + $value = intval($value); + return ($value >= 0 && $value <= 100); + } + +} + +class iCalendar_property_priority extends iCalendar_property { + + var $name = 'PRIORITY'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + // Only integers between 0 and 9 inclusive allowed + if(!parent::is_valid_value($value)) { + return false; + } + return true; + //$value = intval($value); + //return ($value >= 0 && $value <= 9); + } +} + +class iCalendar_property_resources extends iCalendar_property { + + var $name = 'RESOURCES'; + var $val_type = RFC2445_TYPE_TEXT; + var $val_multi = true; + + function construct() { + $this->valid_parameters = array( + 'ALTREP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_status extends iCalendar_property { + + var $name = 'STATUS'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + +/* function is_valid_value($value) { + // This is case-sensitive + switch ($this->parent_component) { + case 'VEVENT': + $allowed = array('TENTATIVE', 'CONFIRMED', 'CANCELLED'); + break; + case 'VTODO': + $allowed = array('NEEDS-ACTION', 'COMPLETED', 'IN-PROCESS', 'CANCELLED'); + break; + case 'VJOURNAL': + $allowed = array('DRAFT', 'FINAL', 'CANCELLED'); + break; + } + return in_array($value, $allowed); + + } +*/ +} + +class iCalendar_property_summary extends iCalendar_property { + + var $name = 'SUMMARY'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + 'ALTREP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +// 4.8.2 Date and Time Component Properties +// ---------------------------------------- + +class iCalendar_property_completed extends iCalendar_property { + + var $name = 'COMPLETED'; + var $val_type = RFC2445_TYPE_DATE_TIME; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + // Time MUST be in UTC format + return(substr($value, -1) == 'Z'); + } +} + +class iCalendar_property_dtend extends iCalendar_property { + + var $name = 'DTEND'; + var $val_type = RFC2445_TYPE_DATE_TIME; + + function construct() { + $this->valid_parameters = array( + 'VALUE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'TZID' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + + // If present in a FREEBUSY component, must be in UTC format + if($this->parent_component == 'VFREEBUSY' && substr($value, -1) != 'Z') { + return false; + } + + return true; + + } + + function is_valid_parameter($parameter, $value) { + + $parameter = strtoupper($parameter); + + if(!parent::is_valid_parameter($parameter, $value)) { + return false; + } + if($parameter == 'VALUE' && !($value == 'DATE' || $value == 'DATE-TIME')) { + return false; + } + + return true; + } +} + +class iCalendar_property_due extends iCalendar_property { + + var $name = 'DUE'; + var $val_type = RFC2445_TYPE_DATE_TIME; + + function construct() { + $this->valid_parameters = array( + 'VALUE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'TZID' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + + // If present in a FREEBUSY component, must be in UTC format + if($this->parent_component == 'VFREEBUSY' && substr($value, -1) != 'Z') { + return false; + } + + return true; + + } + + function is_valid_parameter($parameter, $value) { + + $parameter = strtoupper($parameter); + + if(!parent::is_valid_parameter($parameter, $value)) { + return false; + } + if($parameter == 'VALUE' && !($value == 'DATE' || $value == 'DATE-TIME')) { + return false; + } + + return true; + } +} + +class iCalendar_property_dtstart extends iCalendar_property { + + var $name = 'DTSTART'; + var $val_type = RFC2445_TYPE_DATE_TIME; + + function construct() { + $this->valid_parameters = array( + 'VALUE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'TZID' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + // TODO: unimplemented stuff when parent is a VTIMEZONE component + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + // If present in a FREEBUSY component, must be in UTC format + if($this->parent_component == 'VFREEBUSY' && substr($value, -1) != 'Z') { + return false; + } + + return true; + } + + function is_valid_parameter($parameter, $value) { + $parameter = strtoupper($parameter); + + if(!parent::is_valid_parameter($parameter, $value)) { + return false; + } + if($parameter == 'VALUE' && !($value == 'DATE' || $value == 'DATE-TIME')) { + return false; + } + + return true; + } +} + +class iCalendar_property_duration extends iCalendar_property { + + var $name = 'DURATION'; + var $val_type = RFC2445_TYPE_DURATION; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + + // Value must be positive + return ($value{0} != '-'); + } +} + +class iCalendar_property_freebusy extends iCalendar_property { + + var $name = 'FREEBUSY'; + var $val_type = RFC2445_TYPE_PERIOD; + var $val_multi = true; + + function construct() { + $this->valid_parameters = array( + 'FBTYPE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + + $pos = strpos($value, '/'); // We know there's only one / in there + if($value{$pos - 1} != 'Z') { + // Start time MUST be in UTC + return false; + } + if($value{$pos + 1} != 'P' && $substr($value, -1) != 'Z') { + // If the second part is not a period, it MUST be in UTC + return false; + } + + return true; + } + + // TODO: these properties SHOULD be shorted in ascending order (by start time and end time as tiebreak) +} + +class iCalendar_property_transp extends iCalendar_property { + + var $name = 'TRANSP'; + var $val_type = RFC2445_TYPE_TEXT; + var $val_default = 'OPAQUE'; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + return ($value === 'TRANSPARENT' || $value === 'OPAQUE'); + } +} + +// TODO: 4.8.3 timezone component properties + + +// 4.8.4 Relationship Component Properties +// --------------------------------------- + +class iCalendar_property_attendee extends iCalendar_property { + + var $name = 'ATTENDEE'; + var $val_type = RFC2445_TYPE_CAL_ADDRESS; + + // TODO: MUST NOT be specified when the calendar object has METHOD=PUBLISH + // TODO: standard has lots of detail here, make triple sure that we eventually conform + + function construct() { + $this->valid_parameters = array( + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'CN' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'ROLE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'PARTSTAT' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'RSVP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'CUTYPE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'MEMBER' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DELEGATED-TO' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DELEGATED-FROM' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'SENT-BY' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DIR' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function set_parent_component($componentname) { + if(!parent::set_parent_component($componentname)) { + return false; + } + + if($this->parent_component == 'VFREEBUSY' || $this->parent_component == 'VALARM') { + // Most parameters become invalid in this case, the full allowed set is now: + $this->valid_parameters = array( + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + return false; + } + +} + +class iCalendar_property_contact extends iCalendar_property { + + var $name = 'CONTACT'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + 'ALTREP' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_organizer extends iCalendar_property { + + var $name = 'ORGANIZER'; + var $val_type = RFC2445_TYPE_CAL_ADDRESS; + + function construct() { + $this->valid_parameters = array( + 'CN' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'DIR' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'SENT-BY' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + // TODO: +/* + Conformance: This property MUST be specified in an iCalendar object + that specifies a group scheduled calendar entity. This property MUST + be specified in an iCalendar object that specifies the publication of + a calendar user's busy time. This property MUST NOT be specified in + an iCalendar object that specifies only a time zone definition or + that defines calendar entities that are not group scheduled entities, + but are entities only on a single user's calendar. +*/ + +} + +class iCalendar_property_recurrence_id extends iCalendar_property { + + // TODO: can only be specified when defining recurring components in the calendar +/* + Conformance: This property can be specified in an iCalendar object + containing a recurring calendar component. + + Description: The full range of calendar components specified by a + recurrence set is referenced by referring to just the "UID" property + value corresponding to the calendar component. The "RECURRENCE-ID" + property allows the reference to an individual instance within the + recurrence set. +*/ + + var $name = 'RECURRENCE-ID'; + var $val_type = RFC2445_TYPE_DATE_TIME; + + function construct() { + $this->valid_parameters = array( + 'RANGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'TZID' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'VALUE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_parameter($parameter, $value) { + + $parameter = strtoupper($parameter); + + if(!parent::is_valid_parameter($parameter, $value)) { + return false; + } + if($parameter == 'VALUE' && !($value == 'DATE' || $value == 'DATE-TIME')) { + return false; + } + + return true; + } + +} + +class iCalendar_property_related_to extends iCalendar_property { + + var $name = 'RELATED-TO'; + var $val_type = RFC2445_TYPE_TEXT; + + // TODO: the value of this property must reference another component's UID + + function construct() { + $this->valid_parameters = array( + 'RELTYPE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_url extends iCalendar_property { + + var $name = 'URL'; + var $val_type = RFC2445_TYPE_URI; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_uid extends iCalendar_property { + + var $name = 'UID'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + + // The exception to the rule: this is not a static value, so we + // generate it on-the-fly here. Guaranteed to be different for + // each instance of this property, too. Nice. + $this->val_default = rfc2445_guid(); + } +} + +// 4.8.5 Recurrence Component Properties +// ------------------------------------- + +class iCalendar_property_exdate extends iCalendar_property { + + var $name = 'EXDATE'; + var $val_type = RFC2445_TYPE_DATE_TIME; + var $val_multi = true; + + function construct() { + $this->valid_parameters = array( + 'TZID' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'VALUE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_parameter($parameter, $value) { + + $parameter = strtoupper($parameter); + + if(!parent::is_valid_parameter($parameter, $value)) { + return false; + } + if($parameter == 'VALUE' && !($value == 'DATE' || $value == 'DATE-TIME')) { + return false; + } + + return true; + } + +} + +class iCalendar_property_exrule extends iCalendar_property { + + var $name = 'EXRULE'; + var $val_type = RFC2445_TYPE_RECUR; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_rdate extends iCalendar_property { + + var $name = 'RDATE'; + var $val_type = RFC2445_TYPE_DATE_TIME; + var $val_multi = true; + + function construct() { + $this->valid_parameters = array( + 'TZID' => RFC2445_OPTIONAL | RFC2445_ONCE, + 'VALUE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_parameter($parameter, $value) { + + $parameter = strtoupper($parameter); + + if(!parent::is_valid_parameter($parameter, $value)) { + return false; + } + if($parameter == 'VALUE' && !($value == 'DATE' || $value == 'DATE-TIME' || $value == 'PERIOD')) { + return false; + } + + return true; + } + +} + +class iCalendar_property_rrule extends iCalendar_property { + + var $name = 'RRULE'; + var $val_type = RFC2445_TYPE_RECUR; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +// TODO: 4.8.6 Alarm Component Properties + +// 4.8.7 Change Management Component Properties +// -------------------------------------------- + +class iCalendar_property_created extends iCalendar_property { + + var $name = 'CREATED'; + var $val_type = RFC2445_TYPE_DATE_TIME; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + // Time MUST be in UTC format + return(substr($value, -1) == 'Z'); + } +} + +class iCalendar_property_dtstamp extends iCalendar_property { + + var $name = 'DTSTAMP'; + var $val_type = RFC2445_TYPE_DATE_TIME; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + // Time MUST be in UTC format + return(substr($value, -1) == 'Z'); + } +} + +class iCalendar_property_last_modified extends iCalendar_property { + var $name = 'LAST-MODIFIED'; + var $val_type = RFC2445_TYPE_DATE_TIME; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + // Time MUST be in UTC format + return(substr($value, -1) == 'Z'); + } +} + +class iCalendar_property_sequence extends iCalendar_property { + + var $name = 'SEQUENCE'; + var $val_type = RFC2445_TYPE_INTEGER; + var $val_default = 0; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!parent::is_valid_value($value)) { + return false; + } + $value = intval($value); + return ($value >= 0); + } +} + +// 4.8.8 Miscellaneous Component Properties +// ---------------------------------------- + +class iCalendar_property_x extends iCalendar_property { + + var $name = RFC2445_XNAME; + var $val_type = NULL; + + function construct() { + $this->valid_parameters = array( + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function set_name($name) { + + $name = strtoupper($name); + + if(rfc2445_is_xname($name)) { + $this->name = $name; + return true; + } + + return false; + } +} + +class iCalendar_property_request_status extends iCalendar_property { + + // IMPORTANT NOTE: This property value includes TEXT fields + // separated by semicolons. Unfortunately, auto-value-formatting + // cannot be used in this case. As an exception, the value passed + // to this property MUST be already escaped. + + var $name = 'REQUEST-STATUS'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + 'LANGUAGE' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } + + function is_valid_value($value) { + if(!is_string($value) || empty($value)) { + return false; + } + + $len = strlen($value); + $parts = array(); + $from = 0; + $escch = false; + + for($i = 0; $i < $len; ++$i) { + if($value{$i} == ';' && !$escch) { + // Token completed + $parts[] = substr($value, $from, $i - $from); + $from = $i + 1; + continue; + } + $escch = ($value{$i} == '\\'); + } + // Add one last token with the remaining text; if the value + // ended with a ';' it was illegal, so check that this token + // is not the empty string. + $parts[] = substr($value, $from); + + $count = count($parts); + + // May have 2 or 3 tokens (last one is optional) + if($count != 2 && $count != 3) { + return false; + } + + // REMEMBER: if ANY part is empty, we have an illegal value + + // First token must be hierarchical numeric status (3 levels max) + if(strlen($parts[0]) == 0) { + return false; + } + + if($parts[0]{0} < '1' || $parts[0]{0} > '4') { + return false; + } + + $len = strlen($parts[0]); + + // Max 3 levels, and can't end with a period + if($len > 5 || $parts[0]{$len - 1} == '.') { + return false; + } + + for($i = 1; $i < $len; ++$i) { + if(($i & 1) == 1 && $parts[0]{$i} != '.') { + // Even-indexed chars must be periods + return false; + } + else if(($i & 1) == 0 && ($parts[0]{$i} < '0' || $parts[0]{$i} > '9')) { + // Odd-indexed chars must be numbers + return false; + } + } + + // Second and third tokens must be TEXT, and already escaped, so + // they are not allowed to have UNESCAPED semicolons, commas, slashes, + // or any newlines at all + + for($i = 1; $i < $count; ++$i) { + if(strpos($parts[$i], "\n") !== false) { + return false; + } + + $len = strlen($parts[$i]); + if($len == 0) { + // Cannot be empty + return false; + } + + $parts[$i] .= '#'; // This guard token saves some conditionals in the loop + + for($j = 0; $j < $len; ++$j) { + $thischar = $parts[$i]{$j}; + $nextchar = $parts[$i]{$j + 1}; + if($thischar == '\\') { + // Next char must now be one of ";,\nN" + if($nextchar != ';' && $nextchar != ',' && $nextchar != '\\' && + $nextchar != 'n' && $nextchar != 'N') { + return false; + } + + // OK, this escaped sequence is correct, bypass next char + ++$j; + continue; + } + if($thischar == ';' || $thischar == ',' || $thischar == '\\') { + // This wasn't escaped as it should + return false; + } + } + } + + return true; + } + + function set_value($value) { + // Must override this, otherwise the value would be quoted again + if($this->is_valid_value($value)) { + $this->value = $value; + return true; + } + + return false; + } + +} + +class iCalendar_property_trigger extends iCalendar_property { + + var $name = 'TRIGGER'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_action extends iCalendar_property { + + var $name = 'ACTION'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + 'DISPLAY' => RFC2445_OPTIONAL | RFC2445_ONCE, + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_x_wr_alarmuid extends iCalendar_property { + + var $name = 'X_WR_ALARMUID'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_tzoffsetto extends iCalendar_property { + + var $name = 'TZOFFSETTO'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_daylightc extends iCalendar_property { + + var $name = 'DAYLIGHTC'; + var $val_type = RFC2445_TYPE_INTEGER; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_standardc extends iCalendar_property { + + var $name = 'STANDARDC'; + var $val_type = RFC2445_TYPE_INTEGER; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} + +class iCalendar_property_tzid extends iCalendar_property { + + var $name = 'TZID'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_REQUIRED + ); + } +} + +####################### +/* +class iCalendar_property_class extends iCalendar_property { + + var $name = 'CLASS'; + var $val_type = RFC2445_TYPE_TEXT; + + function construct() { + $this->valid_parameters = array( + RFC2445_XNAME => RFC2445_OPTIONAL + ); + } +} +*/ + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_rfc2445.php b/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_rfc2445.php new file mode 100644 index 00000000..a1625d71 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/iCal/iCalendar_rfc2445.php @@ -0,0 +1,807 @@ + RFC2445_FOLDED_LINE_LENGTH) { + $retval .= substr($string, 0, RFC2445_FOLDED_LINE_LENGTH - 1) . RFC2445_CRLF . ' '; + $string = substr($string, RFC2445_FOLDED_LINE_LENGTH - 1); + } + + $retval .= $string; + + return $retval; + +} + +function rfc2445_unfold($string) { + for($i = 0; $i < strlen(RFC2445_WSP); ++$i) { + $string = str_replace(RFC2445_CRLF.substr(RFC2445_WSP, $i, 1), '', $string); + } + + return $string; +} + +function rfc2445_is_xname($name) { + + // If it's less than 3 chars, it cannot be legal + if(strlen($name) < 3) { + return false; + } + + // If it contains an illegal char anywhere, reject it + if(strspn($name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-') != strlen($name)) { + return false; + } + + // To be legal, it must still start with "X-" + return substr($name, 0, 2) === 'X-'; +} + +function rfc2445_is_valid_value($value, $type) { + + // This branch should only be taken with xname values + if($type === NULL) { + return true; + } + + switch($type) { + case RFC2445_TYPE_CAL_ADDRESS: + case RFC2445_TYPE_URI: + if(!is_string($value)) { + return false; + } + $valid_schemes = array('ftp', 'http', 'ldap', 'gopher', 'mailto', 'news', 'nntp', 'telnet', 'wais', 'file', 'prospero'); + + $pos = strpos($value, ':'); + if(!$pos) { + return false; + } + + $scheme = strtolower(substr($value, 0, $pos)); + $remain = substr($value, $pos + 1); + + if(!in_array($scheme, $valid_schemes)) { + return false; + } + + if($scheme === 'mailto') { + $regexp = '/^[a-zA-Z0-9]+[_a-zA-Z0-9\-]*(\.[_a-z0-9\-]+)*@(([0-9a-zA-Z\-]+\.)+[a-zA-Z][0-9a-zA-Z\-]+|([0-9]{1,3}\.){3}[0-9]{1,3})$/'; + } + else { + $regexp = '/^//(.+(:.*)?@)?(([0-9a-zA-Z\-]+\.)+[a-zA-Z][0-9a-zA-Z\-]+|([0-9]{1,3}\.){3}[0-9]{1,3})(:[0-9]{1,5})?(/.*)?$/'; + } + + return preg_match($regexp, $remain); + break; + + case RFC2445_TYPE_BINARY: + if(!is_string($value)) { + return false; + } + + $len = strlen($value); + + if($len % 4 != 0) { + return false; + } + + for($i = 0; $i < $len; ++$i) { + $ch = $value{$i}; + if(!($ch >= 'a' && $ch <= 'z' || $ch >= 'A' && $ch <= 'Z' || $ch >= '0' && $ch <= '9' || $ch == '-' || $ch == '+')) { + if($ch == '=' && $len - $i <= 2) { + continue; + } + return false; + } + } + return true; + break; + + case RFC2445_TYPE_BOOLEAN: + if(is_bool($value)) { + return true; + } + if(is_string($value)) { + $value = strtoupper($value); + return ($value == 'TRUE' || $value == 'FALSE'); + } + return false; + break; + + case RFC2445_TYPE_DATE: + if(is_int($value)) { + if($value < 0) { + return false; + } + $value = "$value"; + } + else if(!is_string($value)) { + return false; + } + + if(strlen($value) != 8) { + return false; + } + + $y = intval(substr($value, 0, 4)); + $m = intval(substr($value, 4, 2)); + $d = intval(substr($value, 6, 2)); + + return checkdate($m, $d, $y); + break; + + case RFC2445_TYPE_DATE_TIME: + if(!is_string($value) || strlen($value) < 15) { + return false; + } + + return($value{8} == 'T' && + rfc2445_is_valid_value(substr($value, 0, 8), RFC2445_TYPE_DATE) && + rfc2445_is_valid_value(substr($value, 9), RFC2445_TYPE_TIME)); + break; + + case RFC2445_TYPE_DURATION: + if(!is_string($value)) { + return false; + } + + $len = strlen($value); + + if($len < 3) { + // Minimum conformant length: "P1W" + return false; + } + + if($value{0} == '+' || $value{0} == '-') { + $value = substr($value, 1); + --$len; // Don't forget to update this! + } + + if($value{0} != 'P') { + return false; + } + + // OK, now break it up + $num = ''; + $allowed = 'WDT'; + + for($i = 1; $i < $len; ++$i) { + $ch = $value{$i}; + if($ch >= '0' && $ch <= '9') { + $num .= $ch; + continue; + } + if(strpos($allowed, $ch) === false) { + // Non-numeric character which shouldn't be here + return false; + } + if($num === '' && $ch != 'T') { + // Allowed non-numeric character, but no digits came before it + return false; + } + + // OK, $ch now holds a character which tells us what $num is + switch($ch) { + case 'W': + // If duration in weeks is specified, this must end the string + return ($i == $len - 1); + break; + + case 'D': + // Days specified, now if anything comes after it must be a 'T' + $allowed = 'T'; + break; + + case 'T': + // Starting to specify time, H M S are now valid delimiters + $allowed = 'HMS'; + break; + + case 'H': + $allowed = 'M'; + break; + + case 'M': + $allowed = 'S'; + break; + + case 'S': + return ($i == $len - 1); + break; + } + + // If we 're going to continue, reset $num + $num = ''; + + } + + // $num is kept for this reason: if we 're here, we ran out of chars + // therefore $num must be empty for the period to be legal + return ($num === '' && $ch != 'T'); + + break; + + case RFC2445_TYPE_FLOAT: + if(is_float($value)) { + return true; + } + if(!is_string($value) || $value === '') { + return false; + } + + $dot = false; + $int = false; + $len = strlen($value); + for($i = 0; $i < $len; ++$i) { + switch($value{$i}) { + case '-': case '+': + // A sign can only be seen at position 0 and cannot be the only char + if($i != 0 || $len == 1) { + return false; + } + break; + case '.': + // A second dot is an error + // Make sure we had at least one int before the dot + if($dot || !$int) { + return false; + } + $dot = true; + // Make also sure that the float doesn't end with a dot + if($i == $len - 1) { + return false; + } + break; + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + $int = true; + break; + default: + // Any other char is a no-no + return false; + break; + } + } + return true; + break; + + case RFC2445_TYPE_INTEGER: + if(is_int($value)) { + return true; + } + if(!is_string($value) || $value === '') { + return false; + } + + if($value{0} == '+' || $value{0} == '-') { + if(strlen($value) == 1) { + return false; + } + $value = substr($value, 1); + } + + if(strspn($value, '0123456789') != strlen($value)) { + return false; + } + + return ($value >= -2147483648 && $value <= 2147483647); + break; + + case RFC2445_TYPE_PERIOD: + if(!is_string($value) || empty($value)) { + return false; + } + + $parts = explode('/', $value); + if(count($parts) != 2) { + return false; + } + + if(!rfc2445_is_valid_value($parts[0], RFC2445_TYPE_DATE_TIME)) { + return false; + } + + // Two legal cases for the second part: + if(rfc2445_is_valid_value($parts[1], RFC2445_TYPE_DATE_TIME)) { + // It has to be after the start time, so + return ($parts[1] > $parts[0]); + } + else if(rfc2445_is_valid_value($parts[1], RFC2445_TYPE_DURATION)) { + // The period MUST NOT be negative + return ($parts[1]{0} != '-'); + } + + // It seems to be illegal + return false; + break; + + case RFC2445_TYPE_RECUR: + if(!is_string($value)) { + return false; + } + + $parts = explode(';', strtoupper($value)); + + // First of all, we need at least a FREQ and a UNTIL or COUNT part, so... + if(count($parts) < 2) { + return false; + } + + // Let's get that into a more easily comprehensible format + $vars = array(); + foreach($parts as $part) { + + $pieces = explode('=', $part); + // There must be exactly 2 pieces, e.g. FREQ=WEEKLY + if(count($pieces) != 2) { + return false; + } + + // It's illegal for a variable to appear twice + if(isset($vars[$pieces[0]])) { + return false; + } + + // Sounds good + $vars[$pieces[0]] = $pieces[1]; + } + + // OK... now to test everything else + + // FREQ must be the first thing appearing + reset($vars); + if(key($vars) != 'FREQ') { + return false; + } + + // It's illegal to have both UNTIL and COUNT appear + if(isset($vars['UNTIL']) && isset($vars['COUNT'])) { + return false; + } + + // Special case: BYWEEKNO is only valid for FREQ=YEARLY + if(isset($vars['BYWEEKNO']) && $vars['FREQ'] != 'YEARLY') { + return false; + } + + // Special case: BYSETPOS is only valid if another BY option is specified + if(isset($vars['BYSETPOS'])) { + $options = array('BYSECOND', 'BYMINUTE', 'BYHOUR', 'BYDAY', 'BYMONTHDAY', 'BYYEARDAY', 'BYWEEKNO', 'BYMONTH'); + $defined = array_keys($vars); + $common = array_intersect($options, $defined); + if(empty($common)) { + return false; + } + } + + // OK, now simply check if each element has a valid value, + // unsetting them on the way. If at the end the array still + // has some elements, they are illegal. + + if($vars['FREQ'] != 'SECONDLY' && $vars['FREQ'] != 'MINUTELY' && $vars['FREQ'] != 'HOURLY' && + $vars['FREQ'] != 'DAILY' && $vars['FREQ'] != 'WEEKLY' && + $vars['FREQ'] != 'MONTHLY' && $vars['FREQ'] != 'YEARLY') { + return false; + } + unset($vars['FREQ']); + + // Set this, we may need it later + $weekdays = explode(',', RFC2445_WEEKDAYS); + + if(isset($vars['UNTIL'])) { + if(rfc2445_is_valid_value($vars['UNTIL'], RFC2445_TYPE_DATE_TIME)) { + // The time MUST be in UTC format + if(!(substr($vars['UNTIL'], -1) == 'Z')) { + return false; + } + } + else if(!rfc2445_is_valid_value($vars['UNTIL'], RFC2445_TYPE_DATE_TIME)) { + return false; + } + } + unset($vars['UNTIL']); + + + if(isset($vars['COUNT'])) { + if(empty($vars['COUNT'])) { + // This also catches the string '0', which makes no sense + return false; + } + if(strspn($vars['COUNT'], '0123456789') != strlen($vars['COUNT'])) { + return false; + } + } + unset($vars['COUNT']); + + + if(isset($vars['INTERVAL'])) { + if(empty($vars['INTERVAL'])) { + // This also catches the string '0', which makes no sense + return false; + } + if(strspn($vars['INTERVAL'], '0123456789') != strlen($vars['INTERVAL'])) { + return false; + } + } + unset($vars['INTERVAL']); + + + if(isset($vars['BYSECOND'])) { + if($vars['BYSECOND'] == '') { + return false; + } + // Comma also allowed + if(strspn($vars['BYSECOND'], '0123456789,') != strlen($vars['BYSECOND'])) { + return false; + } + $secs = explode(',', $vars['BYSECOND']); + foreach($secs as $sec) { + if($sec == '' || $sec < 0 || $sec > 59) { + return false; + } + } + } + unset($vars['BYSECOND']); + + + if(isset($vars['BYMINUTE'])) { + if($vars['BYMINUTE'] == '') { + return false; + } + // Comma also allowed + if(strspn($vars['BYMINUTE'], '0123456789,') != strlen($vars['BYMINUTE'])) { + return false; + } + $mins = explode(',', $vars['BYMINUTE']); + foreach($mins as $min) { + if($min == '' || $min < 0 || $min > 59) { + return false; + } + } + } + unset($vars['BYMINUTE']); + + + if(isset($vars['BYHOUR'])) { + if($vars['BYHOUR'] == '') { + return false; + } + // Comma also allowed + if(strspn($vars['BYHOUR'], '0123456789,') != strlen($vars['BYHOUR'])) { + return false; + } + $hours = explode(',', $vars['BYHOUR']); + foreach($hours as $hour) { + if($hour == '' || $hour < 0 || $hour > 23) { + return false; + } + } + } + unset($vars['BYHOUR']); + + + if(isset($vars['BYDAY'])) { + if(empty($vars['BYDAY'])) { + return false; + } + + // First off, split up all values we may have + $days = explode(',', $vars['BYDAY']); + + foreach($days as $day) { + $daypart = substr($day, -2); + if(!in_array($daypart, $weekdays)) { + return false; + } + + if(strlen($day) > 2) { + $intpart = substr($day, 0, strlen($day) - 2); + if(!rfc2445_is_valid_value($intpart, RFC2445_TYPE_INTEGER)) { + return false; + } + if(intval($intpart) == 0) { + return false; + } + } + } + } + unset($vars['BYDAY']); + + + if(isset($vars['BYMONTHDAY'])) { + if(empty($vars['BYMONTHDAY'])) { + return false; + } + $mdays = explode(',', $vars['BYMONTHDAY']); + foreach($mdays as $mday) { + if(!rfc2445_is_valid_value($mday, RFC2445_TYPE_INTEGER)) { + return false; + } + $mday = abs(intval($mday)); + if($mday == 0 || $mday > 31) { + return false; + } + } + } + unset($vars['BYMONTHDAY']); + + + if(isset($vars['BYYEARDAY'])) { + if(empty($vars['BYYEARDAY'])) { + return false; + } + $ydays = explode(',', $vars['BYYEARDAY']); + foreach($ydays as $yday) { + if(!rfc2445_is_valid_value($yday, RFC2445_TYPE_INTEGER)) { + return false; + } + $yday = abs(intval($yday)); + if($yday == 0 || $yday > 366) { + return false; + } + } + } + unset($vars['BYYEARDAY']); + + + if(isset($vars['BYWEEKNO'])) { + if(empty($vars['BYWEEKNO'])) { + return false; + } + $weeknos = explode(',', $vars['BYWEEKNO']); + foreach($weeknos as $weekno) { + if(!rfc2445_is_valid_value($weekno, RFC2445_TYPE_INTEGER)) { + return false; + } + $weekno = abs(intval($weekno)); + if($weekno == 0 || $weekno > 53) { + return false; + } + } + } + unset($vars['BYWEEKNO']); + + + if(isset($vars['BYMONTH'])) { + if(empty($vars['BYMONTH'])) { + return false; + } + // Comma also allowed + if(strspn($vars['BYMONTH'], '0123456789,') != strlen($vars['BYMONTH'])) { + return false; + } + $months = explode(',', $vars['BYMONTH']); + foreach($months as $month) { + if($month == '' || $month < 1 || $month > 12) { + return false; + } + } + } + unset($vars['BYMONTH']); + + + if(isset($vars['BYSETPOS'])) { + if(empty($vars['BYSETPOS'])) { + return false; + } + $sets = explode(',', $vars['BYSETPOS']); + foreach($sets as $set) { + if(!rfc2445_is_valid_value($set, RFC2445_TYPE_INTEGER)) { + return false; + } + $set = abs(intval($set)); + if($set == 0 || $set > 366) { + return false; + } + } + } + unset($vars['BYSETPOS']); + + + if(isset($vars['WKST'])) { + if(!in_array($vars['WKST'], $weekdays)) { + return false; + } + } + unset($vars['WKST']); + + + // Any remaining vars must be x-names + if(empty($vars)) { + return true; + } + + foreach($vars as $name => $var) { + if(!rfc2445_is_xname($name)) { + return false; + } + } + + // At last, all is OK! + return true; + + break; + + case RFC2445_TYPE_TEXT: + return true; + break; + + case RFC2445_TYPE_TIME: + if(is_int($value)) { + if($value < 0) { + return false; + } + $value = "$value"; + } + else if(!is_string($value)) { + return false; + } + + if(strlen($value) == 7) { + if(strtoupper(substr($value, -1)) != 'Z') { + return false; + } + $value = substr($value, 0, 6); + } + if(strlen($value) != 6) { + return false; + } + + $h = intval(substr($value, 0, 2)); + $m = intval(substr($value, 2, 2)); + $s = intval(substr($value, 4, 2)); + + return ($h <= 23 && $m <= 59 && $s <= 60); + break; + + case RFC2445_TYPE_UTC_OFFSET: + if(is_int($value)) { + if($value >= 0) { + $value = "+$value"; + } + else { + $value = "$value"; + } + } + else if(!is_string($value)) { + return false; + } + + if(strlen($value) == 7) { + $s = intval(substr($value, 5, 2)); + $value = substr($value, 0, 5); + } + if(strlen($value) != 5 || $value == "-0000") { + return false; + } + + if($value{0} != '+' && $value{0} != '-') { + return false; + } + + $h = intval(substr($value, 1, 2)); + $m = intval(substr($value, 3, 2)); + + return ($h <= 23 && $m <= 59 && $s <= 59); + break; + } + + // TODO: remove this assertion + trigger_error('bad code path', E_USER_WARNING); + var_dump($type); + return false; +} + +function rfc2445_do_value_formatting($value, $type) { + // Note: this does not only do formatting; it also does conversion to string! + switch($type) { + case RFC2445_TYPE_CAL_ADDRESS: + case RFC2445_TYPE_URI: + // Enclose in double quotes + $value = '"'.$value.'"'; + break; + case RFC2445_TYPE_TEXT: + // Escape entities + $value = strtr($value, array("\n" => '\\n', '\\' => '\\\\', ',' => '\\,', ';' => '\\;')); + break; + } + return $value; +} + +function rfc2445_undo_value_formatting($value, $type) { + switch($type) { + case RFC2445_TYPE_CAL_ADDRESS: + case RFC2445_TYPE_URI: + // Trim beginning and end double quote + $value = substr($value, 1, strlen($value) - 2); + break; + case RFC2445_TYPE_TEXT: + // Unescape entities + $value = strtr($value, array('\\n' => "\n", '\\N' => "\n", '\\\\' => '\\', '\\,' => ',', '\\;' => ';')); + break; + } + return $value; +} + +// This is cheating: GUIDs have nothing to do with RFC 2445 + +function rfc2445_guid() { + // Implemented as per the Network Working Group draft on UUIDs and GUIDs + + // These two octets get special treatment + $time_hi_and_version = sprintf('%02x', (1 << 6) + mt_rand(0, 15)); // 0100 plus 4 random bits + $clock_seq_hi_and_reserved = sprintf('%02x', (1 << 7) + mt_rand(0, 63)); // 10 plus 6 random bits + + // Need another 14 random octects + $pool = ''; + for($i = 0; $i < 7; ++$i) { + $pool .= sprintf('%04x', mt_rand(0, 65535)); + } + + // time_low = 4 octets + $random = substr($pool, 0, 8).'-'; + + // time_mid = 2 octets + $random .= substr($pool, 8, 4).'-'; + + // time_high_and_version = 2 octets + $random .= $time_hi_and_version.substr($pool, 12, 2).'-'; + + // clock_seq_high_and_reserved = 1 octet + $random .= $clock_seq_hi_and_reserved; + + // clock_seq_low = 1 octet + $random .= substr($pool, 13, 2).'-'; + + // node = 6 octets + $random .= substr($pool, 14, 12); + + return $random; +} + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/iCal/ical-parser-class.php b/oss/vtiger/trunk/modules/Calendar/iCal/ical-parser-class.php new file mode 100644 index 00000000..ed4d3c32 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/iCal/ical-parser-class.php @@ -0,0 +1,91 @@ +folders = 'cache/import/'; + } + + function iCalReader($filename,$root_directory='') { + $iCaltoArray = $this->iCalDecoder($filename,$root_directory); + return $iCaltoArray; + } + + function iCalDecoder($file,$root_directory) { + $ical = file_get_contents($root_directory.$this->folders.$file); + preg_match_all('/BEGIN:VEVENT.*?END:VEVENT/si', $ical, $eventresult, PREG_PATTERN_ORDER); + preg_match_all('/BEGIN:VTODO.*?END:VTODO/si', $ical, $todoresult, PREG_PATTERN_ORDER); + for ($i = 0; $i < count($eventresult[0]); $i++) { + $tmpbyline = explode("\r\n", $eventresult[0][$i]); + $begin = false; + $key=NULL; + foreach ($tmpbyline as $item) { + $tmpholderarray = explode(":",$item,2); + + if (count($tmpholderarray) >1) { + if($tmpholderarray[0]=='BEGIN'){ + if($begin==false){ + $begin = true; + $majorarray['TYPE']=$tmpholderarray[1]; + } else { + $majorarray[$tmpholderarray[1]]=array(); + $key = $tmpholderarray[1]; + } + } else if($tmpholderarray[0]=='END'){ + if(!empty($key)){ + $key = NULL; + } + } else { + if(!empty($key)){ + $majorarray[$key][$tmpholderarray[0]] = $tmpholderarray[1]; + } else { + $majorarray[$tmpholderarray[0]] = $tmpholderarray[1]; + } + } + } + + } + $icalarray[] = $majorarray; + unset($majorarray); + } + + for ($i = 0; $i < count($todoresult[0]); $i++) { + $tmpbyline = explode("\r\n", $todoresult[0][$i]); + $begin = false; + $key=NULL; + foreach ($tmpbyline as $item) { + $tmpholderarray = explode(":",$item); + + if (count($tmpholderarray) >1) { + if($tmpholderarray[0]=='BEGIN'){ + if($begin==false){ + $begin = true; + $majorarray['TYPE']=$tmpholderarray[1]; + } else { + $majorarray[$tmpholderarray[1]]=array(); + $key = $tmpholderarray[1]; + } + } else if($tmpholderarray[0]=='END'){ + if(!empty($key)){ + $key = NULL; + } + } else { + if(!empty($key)){ + $majorarray[$key][$tmpholderarray[0]] = $tmpholderarray[1]; + } else { + $majorarray[$tmpholderarray[0]] = $tmpholderarray[1]; + } + } + } + + } + $icalarray[] = $majorarray; + unset($majorarray); + } + return $icalarray; + } +} + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/iCalExport.php b/oss/vtiger/trunk/modules/Calendar/iCalExport.php new file mode 100644 index 00000000..6886deb4 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/iCalExport.php @@ -0,0 +1,113 @@ +id . + " and vtiger_activity.activitytype NOT IN ('Emails')"; + +$calendar_results = $adb->query($ical_query); + +// Send the right content type and filename +header ("Content-type: text/calendar"); +header('Content-Disposition: attachment; '."filename={$filename}.ics"); + +$todo_fields = getColumnFields('Calendar'); +$event_fields = getColumnFields('Events'); +$event = $todo = array(); +$keys_to_replace = array( + 'events'=>array('taskpriority'), + 'todo'=>array('taskpriority','taskstatus') +); +$keyvals_to_replace = array( + 'events'=>array('taskpriority'=>'priority'), + 'todo'=>array('taskpriority'=>'priority','taskstatus'=>'status') +); +foreach($todo_fields as $key=>$val){ + if(getFieldVisibilityPermission('Calendar',$current_user->id,$key)==0){ + if(!in_array($key,$keys_to_replace['todo'])){ + $todo[$key] = 'yes'; + } else { + $todo[$keyvals_to_replace['todo'][$key]] = 'yes'; + } + } +} +foreach($event_fields as $key=>$val){ + if(getFieldVisibilityPermission('Events',$current_user->id,$key)==0){ + if(!in_array($key,$keys_to_replace['events'])){ + $event[$key] = 'yes'; + } else { + $event[$keyvals_to_replace['events'][$key]] = 'yes'; + } + } +} + +$tz = new iCalendar_timezone; +if(!empty($default_timezone)){ + $tzid = split('/',$default_timezone); +} else { + $default_timezone = date_default_timezone_get(); + $tzid = split('/',$default_timezone); +} + +if(!empty($tzid[1])){ + $tz->add_property('TZID', $tzid[1]); +} else { + $tz->add_property('TZID', $tzid[0]); +} +$tz->add_property('TZOFFSETTO', date('O')); +if(date('I')==1){ + $tz->add_property('DAYLIGHTC', date('I')); +} else { + $tz->add_property('STANDARDC', date('I')); +} + +$myical = new iCalendar; + +$myical->add_component($tz); + +while (!$calendar_results->EOF) { + $this_event = $calendar_results->fields; + $id = $this_event['activityid']; + $type = $this_event['activitytype']; + if($type!='Task'){ + $temp = $event; + foreach($temp as $key=>$val){ + $temp[$key] = $this_event[$key]; + } + $temp['id'] = $id; + $ev = new iCalendar_event; + $ev->assign_values($temp); + + $al = new iCalendar_alarm; + $al->assign_values($temp); + $ev->add_component($al); + } else { + $temp = $todo; + foreach($temp as $key=>$val){ + $temp[$key] = $this_event[$key]; + } + $ev = new iCalendar_todo; + $ev->assign_values($temp); + } + + $myical->add_component($ev); + $calendar_results->MoveNext(); +} +// Print the actual calendar +echo $myical->serialize(); + +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/iCalImport.php b/oss/vtiger/trunk/modules/Calendar/iCalImport.php new file mode 100644 index 00000000..01440132 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/iCalImport.php @@ -0,0 +1,146 @@ +mark_deleted_by_user_id($current_user->id); + $file_details = $_FILES['ics_file']; + $binFile = 'vtiger_import'.date('YmdHis'); + $file = $import_dir.''.$binFile; + $filetmp_name = $file_details['tmp_name']; + $upload_status = move_uploaded_file($filetmp_name,$file); + + $skip_fields = array( + 'Events'=>array('duration_hours'), + 'Calendar'=>array('eventstatus') + ); + $required_fields = array(); + + $modules = array('Events','Calendar'); + foreach($modules as $module){ + $calendar = CRMEntity::getInstance('Calendar'); + $calendar->initRequiredFields($module); + $val = array_keys($calendar->required_fields); + $required_fields[$module] = array_diff($val,$skip_fields[$module]); + } + + $ical = new iCal(); + $ical_activities = $ical->iCalReader($binFile); + + $count['Events'] = $count['Calendar'] = $skip_count['Events'] = $skip_count['Calendar'] = 0; + for($i=0;$icolumn_fields = $activity->generateArray($ical_activities[$i]); + $calendar->column_fields['assigned_user_id'] = $current_user->id; + foreach($required_fields[$module] as $key){ + if(empty($calendar->column_fields[$key])){ + $skip_count[$module]++; + break; + } + } + $calendar->save('Calendar'); + $last_import = new UsersLastImport(); + $last_import->assigned_user_id = $current_user->id; + $last_import->bean_type = 'Calendar'; + $last_import->bean_id = $calendar->id; + $last_import->save(); + if(!empty($ical_activities[$i]['VALARM'])){ + $calendar->activity_reminder($calendar->id,$calendar->column_fields['reminder_time'],0,'',''); + } + } + unlink($file); + $smarty->assign("IMAGE_PATH", $last_imported); + $smarty = new vtigerCRM_Smarty; + + $smarty->assign("MOD", $mod_strings); + $smarty->assign("APP", $app_strings); + $smarty->assign("IMP", $import_mod_strings); + $smarty->assign("THEME", $theme); + $smarty->assign("IMAGE_PATH", $image_path); + $parent_tab = vtlib_purify($_SESSION['import_parenttab']); + if(empty($parent_Tab)){ + $parent_tab = getParentTab(); + } + $smarty->assign("MODULE", vtlib_purify($_REQUEST['module'])); + $smarty->assign("SINGLE_MOD", vtlib_purify($_REQUEST['module'])); + $smarty->assign("CATEGORY", $parent_tab); + //@session_unregister("import_parenttab"); + $smarty->display("Buttons_List1.tpl"); + + $imported_events = $count['Events'] - $skip_count['Events']; + $imported_tasks = $count['Calendar'] - $skip_count['Calendar']; + $message= "".$mod_strings['LBL_SUCCESS']."" + ."

" .$mod_strings['LBL_SUCCESS_EVENTS_1']." $imported_events" + ."

" .$mod_strings['LBL_SKIPPED_EVENTS_1'].$skip_count['Events'] + ."

" .$mod_strings['LBL_SUCCESS_CALENDAR_1']." $imported_tasks" + ."

" .$mod_strings['LBL_SKIPPED_CALENDAR_1'].$skip_count['Calendar'] + ."

"; + + $smarty->assign("MESSAGE", $message); + $smarty->assign("RETURN_MODULE", $currentModule); + $smarty->assign("RETURN_ACTION", 'ListView'); + $smarty->assign("MODULE", $currentModule); + $smarty->assign("MODULENAME", $currentModule); + $smarty->display("iCalImport.tpl"); + +} else { + $smarty->assign("IMAGE_PATH", $last_imported); + $smarty = new vtigerCRM_Smarty; + + $smarty->assign("MOD", $mod_strings); + $smarty->assign("APP", $app_strings); + $smarty->assign("IMP", $import_mod_strings); + $smarty->assign("THEME", $theme); + $smarty->assign("IMAGE_PATH", $image_path); + $parent_tab = vtlib_purify($_SESSION['import_parenttab']); + if(empty($parent_Tab)){ + $parent_tab = getParentTab(); + } + $smarty->assign("MODULE", vtlib_purify($_REQUEST['module'])); + $smarty->assign("SINGLE_MOD", vtlib_purify($_REQUEST['module'])); + $smarty->assign("CATEGORY", $parent_tab); + //@session_unregister("import_parenttab"); + $smarty->display("Buttons_List1.tpl"); + + $last_import = new UsersLastImport(); + $ret_value = $last_import->undo($current_user->id); + + if(!empty($ret_value)){ + $message= "".$mod_strings['LBL_SUCCESS']."" + ."

" .$mod_strings['LBL_LAST_IMPORT_UNDONE']." "; + } else { + $message= "".$mod_strings['LBL_FAILURE']."" + ."

" .$mod_strings['LBL_NO_IMPORT_TO_UNDO']." "; + } + + $smarty->assign("MESSAGE", $message); + $smarty->assign("UNDO", 'yes'); + $smarty->assign("RETURN_MODULE", $currentModule); + $smarty->assign("RETURN_ACTION", 'ListView'); + $smarty->assign("MODULE", $currentModule); + $smarty->assign("MODULENAME", $currentModule); + $smarty->display("iCalImport.tpl"); +} +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/index.php b/oss/vtiger/trunk/modules/Calendar/index.php new file mode 100644 index 00000000..06bda1f8 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/index.php @@ -0,0 +1,32 @@ + diff --git a/oss/vtiger/trunk/modules/Calendar/language/en_us.lang.php b/oss/vtiger/trunk/modules/Calendar/language/en_us.lang.php new file mode 100644 index 00000000..891c51aa --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/language/en_us.lang.php @@ -0,0 +1,452 @@ +'Calendar', +'LBL_MODULE_TITLE'=>'Calendar: Home', +'LBL_MODULE_APPOINTMENT'=>'Calendar: Appointment', +'LBL_MODULE_APPOINTMENT_DETAIL'=>'Calendar: Appointment Detail', +'LBL_SAVE'=>'Save', +'LBL_RESET'=>'Cancel', +'LBL_LIST_USER_NAME'=>'User Name', +'LBL_LIST_NAME'=>'Name', +'LBL_CALENDAR_SHARED'=>'Calendar currently shared with', +'LBL_CALENDAR_SHARING'=>'Share calendar with', +'LBL_SHARING_OPTION'=>'Can see my calendar?', +'LBL_LIST_TOOLS'=>'Tools', +'LBL_SETTINGS'=>'Settings', +'LBL_CALSETTINGS'=>'Calendar Settings', +'LBL_USE24'=>'Use 24 hours format', +'LBL_CALSTART'=>'Start my calendar time at', +'LBL_TIMESETTINGS'=>'Time Settings', +'LBL_HOLDFOLLOWUP'=>'Hold followup on', +'LBL_CALL' => 'Call', +'LBL_MEET' => 'Meeting', +'LBL_APPNT' => 'Appointment', +'LBL_NEW_APPNT' => 'New Appointment', +'LBL_NEW_APPNT_INFO' => 'Create a new appointment', +'LBL_VIEW_DAY_APPNT_INFO' => 'View appointment(s) for this day', +'LBL_CHANGE_APPNT' => 'see or change this appointment (%s - %s)', + +'LBL_DAY' => 'Day', +'LBL_DAY_BUTTON_KEY' => 'D', +'LBL_DAY_BUTTON_TITLE' => 'Day [Alt+D]', +'LBL_DAY1' => 'Monday', +'LBL_DAY2' => 'Tuesday', +'LBL_DAY3' => 'Wednesday', +'LBL_DAY4' => 'Thursday', +'LBL_DAY5' => 'Friday', +'LBL_DAY6' => 'Saturday', +'LBL_DAY0' => 'Sunday', + +'LBL_SM_MON' => 'Mon', +'LBL_SM_TUE' => 'Tue', +'LBL_SM_WED' => 'Wed', +'LBL_SM_THU' => 'Thu', +'LBL_SM_FRI' => 'Fri', +'LBL_SM_SAT' => 'Sat', +'LBL_SM_SUN' => 'Sun', + +'LBL_DATE_TITLE' => 'Day %d, %A', + +'LBL_WEEK' => 'Week', +'LBL_WEEK_BUTTON_KEY' => 'W', +'LBL_WEEK_BUTTON_TITLE' => 'Week [Alt+W]', +'LBL_WEEKS' => 'Weeks', +'LBL_NEXT_WEEK' => 'next week', +'LBL_LAST_WEEK' => 'last week', +'LBL_4WEEKS_BACK' => '4 weeks back', +'LBL_4WEEKS_PLUS' => '4 weeks plus', +'LBL_RELOAD' => 'Reload', + + +'LBL_APPCREATED_BY' => 'Created by', +'LBL_AT_DATE_TIME' => 'at', + +'LBL_MON' => 'Month', +'LBL_MON_BUTTON_KEY' => 'M', +'LBL_MON_BUTTON_TITLE' => 'Month [Alt+M]', +'LBL_PREV_MON' => 'Previous Month', +'LBL_NEXT_MON' => 'Next Month', + +'LBL_YEAR_BUTTON_KEY'=>'Y', +'LBL_PREV_YEAR'=>'Previous Year', +'LBL_NEXT_YEAR' => 'Next Year', + +'LBL_APP_LOCATION' => 'Location', +'LBL_APP_IGNORE_TIME' => 'ignore above times', +'LBL_SUBJECT'=>'Subject:', +'LBL_APP_DESCRIPTION' => 'Description', +'LBL_CONTACT'=>'Contact:', +'LBL_CONTACT_LIST'=>'Contact List:', + +'LBL_APP_IGNORE_TIME2' => '(i.e. the appointment takes place
at no particular time on these day(s) )', + +'LBL_APP_ERR001' =>'Invalid Date in field %s!', +'LBL_APP_ERR002' =>'start after end !', +'LBL_APP_ERR003' =>'Missing Contact !', +'LBL_APP_ERR004' =>'Missing Subject !', +'ERR_DELETE_RECORD'=>"A record number must be specified to delete the appointment.", +'DELETE_CONFIRMATION'=>"Are you sure you want to delete this appointment?", + +'AppLoc'=> Array('0' => 'Office' + , '1' => 'Out' + , '2' => 'Vacation' + , '3' => 'sick' + , '4' => 'Postponed' + , '5' => 'Option' + , '6' => 'Private'), + +'cal_month_long'=>array( +"", +"January", +"February", +"March", +"April", +"May", +"June", +"July", +"August", +"September", +"October", +"November", +"December", +), + +'cal_weekdays_short'=>array( +"Sun", +"Mon", +"Tue", +"Wed", +"Thu", +"Fri", +"Sat", +), +'cal_weekdays_long'=>array( +"Sunday", +"Monday", +"Tuesday", +"Wednesday", +"Thursday", +"Friday", +"Saturday", +), +'cal_month_short'=>array( +"", +"Jan", +"Feb", +"Mar", +"Apr", +"May", +"Jun", +"Jul", +"Aug", +"Sep", +"Oct", +"Nov", +"Dec", +), + +'LBL_TIME'=>'Time', +'LBL_START_TIME' => 'Start Time', +'LBL_END_TIME' => 'End Time', +'LBL_START_DATE'=>'Start Date', +'LBL_TIME_START'=>'Time Start', +'LBL_DUE_DATE'=>'Due Date', +'LBL_START_DATE_TIME'=>'Start Date & Time', +'LBL_END_DATE_TIME'=>'End Date & Time', +'LBL_TODO'=>'To Do', +'LBL_TODOS'=>'To Dos', +'LBL_EVENTS'=>'Events', +'LBL_TOTALEVENTS'=>'My Total Events :', +'LBL_TOTALTODOS'=>'My Total To Dos :', +'LBL_VIEW'=>'View', +'LBL_LISTVIEW'=>'List View', +'LBL_HRVIEW'=>'Hour View', +'LBL_WEEKVIEW'=>'Weekly Calendar View', +'LBL_MONTHVIEW'=>'Monthly Calendar View', +'LBL_YEARVIEW'=>'Yearly Calendar View', +'LBL_STATUS'=>'Status', +'LBL_ACTION'=>'Actions', +'LBL_ADD'=>'Add', +'LBL_OPENCAL'=>'Open Calendar', + + +'LBL_ADD_EVENT'=>'Add Event', +'LBL_ADDCALL'=>'Call', +'LBL_ADDMEETING'=>'Meeting', +'LBL_ADDTODO'=>'To Do', +'LBL_BEFOREEVENT'=>'before the event starts', +'LBL_BEFORETASK'=>'before the task starts', +'LBL_EVENTDETAILS'=>'Event Details', +'LBL_CURSTATUS'=>'Current Status', +'LBL_ASSINGEDTO'=>'Assigned To', +'LBL_RELATEDTO'=>'Related To', +'LBL_PENDING'=>'Pending', +'LBL_PUBLIC'=>'Mark Public', +'LBL_MORE'=>'More', +'LBL_EDIT'=>'Edit', +'LBL_EVERYDAY'=>'Every Day', +'LBL_EVERYWEEK'=>'Every Week', +'LBL_EVERYMON'=>'Every Month', +'LBL_WEEKS'=>'Week(s)', +'LBL_MONTHS'=>'Month(s)', +'LBL_YEAR'=>'Year', +'LBL_NONE_SCHEDULED'=>'None Scheduled', + +'LBL_INVITE_INST1'=>'To invite, select the users from the "Available Users" list and click the "Add" button.', +'LBL_INVITE_SHARE'=>'To share, select the users from the "Available Users" list and click the "Add" button.', +'LBL_INVITE_INST2'=>'To remove, select the users from the "Selected Users" list and the click "Remove" button.', +'LBL_SELUSR_INFO'=>' Selected users will receive an email about the Event.', +'LBL_CALSHAREMESSAGE'=>'Share my calendar with the following selected users', +'LBL_CALSHARE'=>'Calendar Sharing', +'LBL_SEL_USERS'=>'Selected Users', +'LBL_AVL_USERS'=>'Available Users', +'LBL_ADD_BUTTON'=>'Add', +'LBL_USERS'=>'Users', +'LBL_RMV_BUTTON'=>'Remove', +'LBL_SDRMD'=>'Send Reminder to', +'LBL_ENABLE_REPEAT'=>'Enable Repeat', +'LBL_REPEAT_ONCE'=>'Repeat once in every', +'LBL_ADD_TODO'=>'Create To Do', +'LBL_TODONAME'=>'To Do', +'LBL_TODODATETIME'=>'Time & Date', + + + + + +//DON'T CONVERT THESE THEY ARE MAPPINGS - STARTS +'db_last_name' => 'LBL_LIST_LAST_NAME', +'db_first_name' => 'LBL_LIST_FIRST_NAME', +'db_title' => 'LBL_LIST_TITLE', +'db_email1' => 'LBL_LIST_EMAIL_ADDRESS', +'db_email2' => 'LBL_LIST_EMAIL_ADDRESS', +//DON'T CONVERT THESE THEY ARE MAPPINGS -ENDS +'LBL_COMPLETED'=>'Mark Completed', +'LBL_DEFERRED'=>'Mark Deferred', +'LBL_HELD'=>'Mark Held', +'LBL_NOTHELD'=>'Mark Not Held', +'LBL_POSTPONE'=>'Postpone', +'LBL_CHANGEOWNER'=>'Change Owner', +'LBL_DEL'=>'Delete', + +//Added for actvity merge with calendar +'LBL_SEARCH_FORM_TITLE'=>'Activity Search', +'LBL_LIST_FORM_TITLE'=>'Activity List', +'LBL_NEW_FORM_TITLE'=>'New Activity', +'LBL_TASK_INFORMATION'=>'Task Information', +'LBL_EVENT_INFORMATION'=>'Event Information', +'LBL_CALENDAR_INFORMATION'=>'Calendar Information', + +'LBL_NAME'=>'Subject:', +'LBL_ACTIVITY_NOTIFICATION'=>'This is a notification that an activity is assigned to you that has been', +'LBL_ACTIVITY_INVITATION'=>'You have been invited for an activity that has been ', +'LBL_DETAILS_STRING'=>'The details are', +'LBL_REGARDS_STRING'=>'Thanks & Regards', +'LBL_CONTACT_NAME'=>'Contact Name', +'LBL_OPEN_ACTIVITIES'=>'Open Activities', +'LBL_ACTIVITY'=>'Activity:', +'LBL_HISTORY'=>'History', +'LBL_UPCOMING'=>"My Upcoming and Pending Activities", +'LBL_TODAY'=>'through ', + +'LBL_NEW_TASK_BUTTON_TITLE'=>'New Task [Alt+N]', +'LBL_NEW_TASK_BUTTON_KEY'=>'N', +'LBL_NEW_TASK_BUTTON_LABEL'=>'New Task', +'LBL_SCHEDULE_MEETING_BUTTON_TITLE'=>'Schedule Meeting [Alt+M]', +'LBL_SCHEDULE_MEETING_BUTTON_KEY'=>'M', +'LBL_SCHEDULE_MEETING_BUTTON_LABEL'=>'Schedule Meeting', +'LBL_SCHEDULE_CALL_BUTTON_TITLE'=>'Schedule Call [Alt+C]', +'LBL_SCHEDULE_CALL_BUTTON_KEY'=>'C', +'LBL_SCHEDULE_CALL_BUTTON_LABEL'=>'Schedule Call', +'LBL_NEW_NOTE_BUTTON_TITLE'=>'New Document [Alt+T]', +'LBL_NEW_ATTACH_BUTTON_TITLE'=>'Attach File [Alt+F]', +'LBL_NEW_NOTE_BUTTON_KEY'=>'T', +'LBL_NEW_ATTACH_BUTTON_KEY'=>'F', +'LBL_NEW_NOTE_BUTTON_LABEL'=>'New Document', +'LBL_NEW_ATTACH_BUTTON_LABEL'=>'Attach File', +'LBL_TRACK_EMAIL_BUTTON_TITLE'=>'Track Email [Alt+K]', +'LBL_TRACK_EMAIL_BUTTON_KEY'=>'K', +'LBL_TRACK_EMAIL_BUTTON_LABEL'=>'Track Email', + +'LBL_LIST_CLOSE'=>'Close', +'LBL_LIST_STATUS'=>'Status', +'LBL_LIST_CONTACT'=>'Contact', +//Added for 4.2 release for Account column support as shown by Fredy +'LBL_LIST_ACCOUNT'=>'Account', +'LBL_LIST_RELATED_TO'=>'Related to', +'LBL_LIST_DUE_DATE'=>'Due Date', +'LBL_LIST_DATE'=>'Date', +'LBL_LIST_SUBJECT'=>'Subject', +'LBL_LIST_LAST_MODIFIED'=>'Last Modified', +'LBL_LIST_RECURRING_TYPE'=>'Recurring Type', + +'ERR_DELETE_RECORD'=>"A record number must be specified to delete the vtiger_account.", +'NTC_NONE_SCHEDULED'=>'None scheduled.', + +// Added vtiger_fields for Attachments in Activities/SubPanelView.php +'LBL_ATTACHMENTS'=>'Attachments', +'LBL_NEW_ATTACHMENT'=>'New Attachment', + +//Added vtiger_fields after RC1 - Release +'LBL_ALL'=>'All', +'LBL_CALL'=>'Call', +'LBL_MEETING'=>'Meeting', +'LBL_TASK'=>'Task', + +//Added for 4GA Release +'Subject'=>'Subject', +'Assigned To'=>'Assigned To', +'Start Date & Time'=>'Start Date & Time', +'Time Start'=>'Time Start', +'Due Date'=>'Due Date', +'Related To'=>'Related to', +'Contact Name'=>'Contact Name', +'Status'=>'Status', +'Priority'=>'Priority', +'Visibility'=>'Visibility', +'Send Notification'=>'Send Notification', +'Created Time'=>'Created Time', +'Modified Time'=>'Modified Time', +'Activity Type'=>'Activity Type', +'Description'=>'Description', +'Duration'=>'Duration', +'Duration Minutes'=>'Duration Minutes', +'Location'=>'Location', +'No Time'=>'No Time', +//Added for Send Reminder 4.2 release +'Send Reminder'=>'Send Reminder', +'LBL_YES'=>'Yes', +'LBL_NO'=>'No', +'LBL_DAYS'=>'day(s)', +'LBL_MINUTES'=>'minutes', +'LBL_HOURS'=>'hours', +'LBL_BEFORE_EVENT'=>'before event', +//Added for CustomView 4.2 Release +'Close'=>'Close', +'Start Date'=>'Start Date', +'Type'=>'Type', +'End Date'=>'End Date', +'Recurrence'=> 'Recurring Events', +'Recurring Type'=> 'Recurring Type', +//Activities - Notification Error +'LBL_NOTIFICATION_ERROR'=>'Mail Error : Please check your outgoing mail server configuration in Settings->Outgoing Mail Server Configuration OR MailId for the present user is not Configured', +// Mike Crowe Mod --------------------------------------------------------added for generic search +'LBL_GENERAL_INFORMATION'=>'General Information', + +'LBL_EVENTTYPE'=>'Event Type', +'LBL_EVENTNAME'=>'Event Name', +'LBL_EVENTSTAT'=>'Event starts at', +'LBL_EVENTEDAT'=>'Event ends on', +'LBL_INVITE'=>'Invite', +'LBL_REPEAT'=>'Repeat', +'LBL_REMINDER'=>'Reminder', +'LBL_SENDREMINDER'=>'Send Reminder', +'LBL_NOTIFICATION'=>'Notification', +'LBL_SENDNOTIFICATION'=>'Send Notification', +'LBL_RMD_ON'=>'Remind on', +'LBL_REPEATEVENT'=>'Repeat once in every', +'LBL_TIMEDATE'=>'Time & Date', +'LBL_HR'=>'Hr', +'LBL_MIN'=>'min', +'LBL_EVENT'=>'Event', +'Daily'=>'Day(s)', +'Weekly'=>'Week(s)', +'Monthly'=>'Month(s)', +'Yearly'=>'Year', +'createdtime'=>'Created Time', +'modifiedtime'=>'Modified Time', +'first'=>'First', +'last'=>'Last', +'High'=>'High', +'Medium'=>'Medium', +'Low'=>'Low', +'LBL_SELECT'=>'Select', +'LBL_ALL_EVENTS_TODOS'=>'All Events & Todos', +'First'=>'First', +'Last'=>'Last', +'on'=>'on', +'day of the month'=>'day of the month', +'Private'=>'Private', +'Public'=>'Public', + +//Added for existing Picklist entries + +'Planned'=>'Planned', +'Held'=>'Held', +'Not Held'=>'Not Held', +'Completed'=>'Completed', +'Deferred'=>'Deferred', +'Not Started'=>'Not Started', +'In Progress'=>'In Progress', +'Pending Input'=>'Pending Input', +'LBL_REMAINDER_DAY'=>'days', +'LBL_REMAINDER_HRS'=>'hrs', +'Call'=>'Call', +'Meeting'=>'Meeting', + +//added to send dates and time in calendar notification/invitation mail. + +'Start date and time'=>'Start Date & Time', +'End date and time'=>'End Date & Time', +//this is for task +'End date'=>'End date', +'LBL_SET_DATE'=>'Set date..', +'Recurrence'=>'Recurrence', + +//added to send invitation mail Subject. +'INVITATION'=>' Invitation ', + +// Added/Updated for vtiger CRM 5.0.4 +'LBL_YEAR_BUTTON_TITLE'=>'Year [Alt+Y]', +'LBL_SELECT_CONTACT'=>'Select Contacts', +'SHARED_EVENT_DEL_MSG'=>'The User does not have permission to Edit/Delete Shared Event.', +//added to fix ticket#4525 +'LBL_CREATED'=>'created', +'LBL_UPDATED'=>'updated', + +//Added after 5.0.4 GA +'LBL_BUSY' => 'Busy', + +//Custom Fields support for Calendar +'LBL_CUSTOM_INFORMATION'=>'Custom Information', + +// Repeat Event support for Calendar +'LBL_UNTIL' => 'Until', +'LBL_SET_DATE'=>'Set Date', + +'LBL_MINE' =>'Mine', +'LBL_SUCCESS_CALENDAR_1' => 'No. of Tasks Successfully Imported : ', +'LBL_SKIPPED_CALENDAR_1' => 'No. of Tasks Skipped as they were missing one or more required fields : ', +'LBL_SUCCESS_EVENTS_1' => 'No. of Events Successfully Imported : ', +'LBL_SKIPPED_EVENTS_1' => 'No. of Events Skipped as they were missing one or more required fields : ', +'LBL_FINISHED'=>'Finished', +'LBL_UNDO_LAST_IMPORT'=>'Undo Last Import', +'LBL_LAST_IMPORT'=>'Last Imported', +'LBL_LAST_IMPORT_UNDONE'=>'Your Last Import Was Undone', +'LBL_SUCCESS'=>'Success!', +'LBL_NO_IMPORT_TO_UNDO'=>'There was no import to undo.', +'LBL_FAILURE'=>'Failed!', +); + +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/language/zh_cn.lang.php b/oss/vtiger/trunk/modules/Calendar/language/zh_cn.lang.php new file mode 100644 index 00000000..661071bb --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/language/zh_cn.lang.php @@ -0,0 +1,453 @@ +'计划任务', +'LBL_MODULE_TITLE'=>'计划任务:首页', +'LBL_MODULE_APPOINTMENT'=>'计划任务:预约', +'LBL_MODULE_APPOINTMENT_DETAIL'=>'计划任务:预约明细', +'LBL_SAVE'=>'保存', +'LBL_RESET'=>'取消', +'LBL_LIST_USER_NAME'=>'账号', +'LBL_LIST_NAME'=>'名称', +'LBL_CALENDAR_SHARED'=>'计划目前分享给', +'LBL_CALENDAR_SHARING'=>'分享计划给', +'LBL_SHARING_OPTION'=>'可以检视我的计划?', +'LBL_LIST_TOOLS'=>'工具', +'LBL_SETTINGS'=>'设定', +'LBL_CALSETTINGS'=>'计划任务设定', +'LBL_USE24'=>'使用24小时制', +'LBL_CALSTART'=>'计划任务开始时间', +'LBL_TIMESETTINGS'=>'时间设定', +'LBL_HOLDFOLLOWUP'=>'稍后处理', +'LBL_CALL'=>'电话记录', +'LBL_MEET'=>'会议', +'LBL_APPNT'=>'行程', +'LBL_NEW_APPNT'=>'新增行程', +'LBL_NEW_APPNT_INFO'=>'建立一笔新的行程', +'LBL_VIEW_DAY_APPNT_INFO'=>'浏览今天的行程', +'LBL_CHANGE_APPNT'=>'察看或变更这个行程(%s-%s)', + +'LBL_DAY'=>'日', +'LBL_DAY_BUTTON_KEY'=>'D', +'LBL_DAY_BUTTON_TITLE'=>'日[Alt+D]', +'LBL_DAY1'=>'星期一', +'LBL_DAY2'=>'星期二', +'LBL_DAY3'=>'星期三', +'LBL_DAY4'=>'星期四', +'LBL_DAY5'=>'星期五', +'LBL_DAY6'=>'星期六', +'LBL_DAY0'=>'星期日', + +'LBL_SM_MON'=>'一', +'LBL_SM_TUE'=>'二', +'LBL_SM_WED'=>'三', +'LBL_SM_THU'=>'四', +'LBL_SM_FRI'=>'五', +'LBL_SM_SAT'=>'六', +'LBL_SM_SUN'=>'日', + +'LBL_DATE_TITLE'=>'Day%d,%A', + +'LBL_WEEK'=>'周', +'LBL_WEEK_BUTTON_KEY'=>'W', +'LBL_WEEK_BUTTON_TITLE'=>'周[Alt+W]', +'LBL_WEEKS'=>'周', +'LBL_NEXT_WEEK'=>'下周', +'LBL_LAST_WEEK'=>'上周', +'LBL_4WEEKS_BACK'=>'四周前', +'LBL_4WEEKS_PLUS'=>'四周后', +'LBL_RELOAD'=>'重新载入', + + +'LBL_APPCREATED_BY'=>'创建人:', +'LBL_AT_DATE_TIME'=>'在', + +'LBL_MON'=>'月', +'LBL_MON_BUTTON_KEY'=>'M', +'LBL_MON_BUTTON_TITLE'=>'月[Alt+M]', +'LBL_PREV_MON'=>'上个月', +'LBL_NEXT_MON'=>'下个月', + +'LBL_YEAR_BUTTON_KEY'=>'Y', +'LBL_PREV_YEAR'=>'去年', +'LBL_NEXT_YEAR'=>'明年', + +'LBL_APP_LOCATION'=>'所在地', +'LBL_APP_IGNORE_TIME'=>'忽略', +'LBL_SUBJECT'=>'主题:', +'LBL_APP_DESCRIPTION'=>'描述', +'LBL_CONTACT'=>'联系方式:', +'LBL_CONTACT_LIST'=>'联系人列表:', + +'LBL_APP_IGNORE_TIME2'=>'(注:这个行程在该期间没有特定的时间)', + +'LBL_APP_ERR001'=>'字段 %s 数据类型错误!', +'LBL_APP_ERR002'=>'开始日期在结束日期之后!', +'LBL_APP_ERR003'=>'联系人为空!', +'LBL_APP_ERR004'=>'标题为空!', +'ERR_DELETE_RECORD'=>'在删除行程前必须输入正确的记录编号.', +'DELETE_CONFIRMATION'=>'您确定要删除这次的行程?', + +'AppLoc'=>Array('0'=>'Office' + , '1' => '户外' + , '2' => '休假' + , '3' => '病假' + , '4' => '延期' + , '5' => '任意' + , '6' => '私人'), + +'cal_month_long'=>array( +"", +"一月", +"二月", +"三月", +"四月", +"五月", +"六月", +"七月", +"八月", +"九月", +"十月", +"十一月", +"十二月", +), + +'cal_weekdays_short'=>array( +"日", +"一", +"二", +"三", +"四", +"五", +"六", +), +'cal_weekdays_long'=>array( +"星期日", +"星期一", +"星期二", +"星期三", +"星期四", +"星期五", +"星期六", +), +'cal_month_short'=>array( +"", +"一月", +"二月", +"三月", +"四月", +"五月", +"六月", +"七月", +"八月", +"九月", +"十月", +"十一月", +"十二月", +), + +'LBL_TIME'=>'时间', +'LBL_START_TIME'=>'开始时间', +'LBL_END_TIME'=>'结束时间', +'LBL_START_DATE'=>'开始日期', +'LBL_TIME_START'=>'时间开始', +'LBL_DUE_DATE'=>'到期日', +'LBL_START_DATE_TIME'=>'开始日期&时间', +'LBL_END_DATE_TIME'=>'结束日期&时间', +'LBL_TODO'=>'待办', +'LBL_TODOS'=>'待办事项', +'LBL_EVENTS'=>'事件', +'LBL_TOTALEVENTS'=>'我的全部事件:', +'LBL_TOTALTODOS'=>'我的待办事项:', +'LBL_VIEW'=>'查看', +'LBL_LISTVIEW'=>'列表查看', +'LBL_HRVIEW'=>'查看时间', +'LBL_WEEKVIEW'=>'查看周历', +'LBL_MONTHVIEW'=>'查看月历', +'LBL_YEARVIEW'=>'查看年历', +'LBL_STATUS'=>'状态', +'LBL_ACTION'=>'操作', +'LBL_ADD'=>'添加', +'LBL_OPENCAL'=>'打开日历', + + +'LBL_ADD_EVENT'=>'添加事件', +'LBL_ADDCALL'=>'呼叫', +'LBL_ADDMEETING'=>'会议', +'LBL_ADDTODO'=>'待办', +'LBL_BEFOREEVENT'=>'在事件开始之前', +'LBL_BEFORETASK'=>'在任务开始之前', +'LBL_EVENTDETAILS'=>'事件细节', +'LBL_CURSTATUS'=>'当前状态', +'LBL_ASSINGEDTO'=>'分配给', +'LBL_RELATEDTO'=>'关联于', +'LBL_PENDING'=>'即将发生', +'LBL_PUBLIC'=>'标记为公共', +'LBL_MORE'=>'更多', +'LBL_EDIT'=>'编辑', +'LBL_EVERYDAY'=>'每天', +'LBL_EVERYWEEK'=>'每周', +'LBL_EVERYMON'=>'每月', +'LBL_WEEKS'=>'周', +'LBL_MONTHS'=>'月', +'LBL_YEAR'=>'年', +'LBL_NONE_SCHEDULED'=>'没有任何行程', + +'LBL_INVITE_INST1'=>'邀请的方式可以从目前使用者列表选择并且点选新增按钮', +'LBL_INVITE_SHARE'=>'分享的方式可以从目前使用者列表选择并且点选新增按钮.', +'LBL_INVITE_INST2'=>'移除邀请的人可以从选择的使用者列表选择并且点选移除按钮', +'LBL_SELUSR_INFO'=>'选择的使用者会收到一封事件的通知。', +'LBL_CALSHAREMESSAGE'=>'开放我的行事历给下面选择的使用者', +'LBL_CALSHARE'=>'共享行事历', +'LBL_SEL_USERS'=>'已选择用户', +'LBL_AVL_USERS'=>'可选择用户', +'LBL_ADD_BUTTON'=>'新增', +'LBL_USERS'=>'用户', +'LBL_RMV_BUTTON'=>'删除', +'LBL_SDRMD'=>'发送提醒讯息', +'LBL_ENABLE_REPEAT'=>'启用循环', +'LBL_REPEAT_ONCE'=>'循环频率', +'LBL_ADD_TODO'=>'建立待办事项', +'LBL_TODONAME'=>'待办事项', +'LBL_TODODATETIME'=>'时间与日期', + + + + + +//DON'T CONVERT THESE THEY ARE MAPPINGS - STARTS +'db_last_name'=>'LBL_LIST_LAST_NAME', +'db_first_name'=>'LBL_LIST_FIRST_NAME', +'db_title'=>'LBL_LIST_TITLE', +'db_email1'=>'LBL_LIST_EMAIL_ADDRESS', +'db_email2'=>'LBL_LIST_EMAIL_ADDRESS', +//DON'T CONVERT THESE THEY ARE MAPPINGS -ENDS +'LBL_COMPLETED'=>'标示为完成', +'LBL_DEFERRED'=>'标示为延缓', +'LBL_HELD'=>'标示为执行', +'LBL_NOTHELD'=>'标示为不执行', +'LBL_POSTPONE'=>'延期', +'LBL_CHANGEOWNER'=>'修改负责人', +'LBL_DEL'=>'删除', + +//Added for actvity merge with calendar +'LBL_SEARCH_FORM_TITLE'=>'搜索待办事项', +'LBL_LIST_FORM_TITLE'=>'待办事项列表', +'LBL_NEW_FORM_TITLE'=>'新增待办事项', +'LBL_TASK_INFORMATION'=>'任务信息', +'LBL_EVENT_INFORMATION'=>'事件信息', +'LBL_CALENDAR_INFORMATION'=>'日历信息', + +'LBL_NAME'=>'主题:', +'LBL_ACTIVITY_NOTIFICATION'=>'这是通知活动分配给你', +'LBL_ACTIVITY_INVITATION'=>'你被邀请参与一个活动', +'LBL_DETAILS_STRING'=>'细节是', +'LBL_REGARDS_STRING'=>'感谢和问候', +'LBL_CONTACT_NAME'=>'联系人', +'LBL_OPEN_ACTIVITIES'=>'进行中事项', +'LBL_ACTIVITY'=>'待办事项:', +'LBL_HISTORY'=>'纪录', +'LBL_UPCOMING'=>'即将到来与等待中待办事项', +'LBL_TODAY'=>'到', + +'LBL_NEW_TASK_BUTTON_TITLE'=>'新增任务[Alt+N]', +'LBL_NEW_TASK_BUTTON_KEY'=>'N', +'LBL_NEW_TASK_BUTTON_LABEL'=>'新增任务', +'LBL_SCHEDULE_MEETING_BUTTON_TITLE'=>'安排会议[Alt+M]', +'LBL_SCHEDULE_MEETING_BUTTON_KEY'=>'M', +'LBL_SCHEDULE_MEETING_BUTTON_LABEL'=>'安排会议', +'LBL_SCHEDULE_CALL_BUTTON_TITLE'=>'安排电话[Alt+C]', +'LBL_SCHEDULE_CALL_BUTTON_KEY'=>'C', +'LBL_SCHEDULE_CALL_BUTTON_LABEL'=>'安排电话', +'LBL_NEW_NOTE_BUTTON_TITLE'=>'新增记事[Alt+T]', +'LBL_NEW_ATTACH_BUTTON_TITLE'=>'附加档案[Alt+F]', +'LBL_NEW_NOTE_BUTTON_KEY'=>'T', +'LBL_NEW_ATTACH_BUTTON_KEY'=>'F', +'LBL_NEW_NOTE_BUTTON_LABEL'=>'新增记事', +'LBL_NEW_ATTACH_BUTTON_LABEL'=>'附加档案', +'LBL_TRACK_EMAIL_BUTTON_TITLE'=>'追踪邮件[Alt+K]', +'LBL_TRACK_EMAIL_BUTTON_KEY'=>'K', +'LBL_TRACK_EMAIL_BUTTON_LABEL'=>'追踪邮件', + +'LBL_LIST_CLOSE'=>'关闭', +'LBL_LIST_STATUS'=>'状态', +'LBL_LIST_CONTACT'=>'联系人', +//Added for 4.2 release for Account column support as shown by Fredy +'LBL_LIST_ACCOUNT'=>'客户', +'LBL_LIST_RELATED_TO'=>'相关于', +'LBL_LIST_DUE_DATE'=>'结束日期', +'LBL_LIST_DATE'=>'日期', +'LBL_LIST_SUBJECT'=>'主旨1', +'LBL_LIST_LAST_MODIFIED'=>'最后更新', +'LBL_LIST_RECURRING_TYPE'=>'循环类型', + +'ERR_DELETE_RECORD'=>"一个记录编号必须被指定删除vtiger_account.", +'NTC_NONE_SCHEDULED'=>'没有安排.', + +// Added vtiger_fields for Attachments in Activities/SubPanelView.php +'LBL_ATTACHMENTS'=>'附加档案', +'LBL_NEW_ATTACHMENT'=>'新增附加档案', + +//Added vtiger_fields after RC1 - Release +'LBL_ALL'=>'全部', +'LBL_CALL'=>'呼叫', +'LBL_MEETING'=>'会议', +'LBL_TASK'=>'任务', + +//Added for 4GA Release +'Subject'=>'主题', +'Assigned To'=>'指定给', +'Start Date & Time'=>'开始日期与时间', +'Time Start'=>'开始时间', +'Due Date'=>'到期日', +'Related To'=>'相关于', +'Contact Name'=>'联系人名称', +'Status'=>'状态', +'Priority'=>'优先级', +'Visibility'=>'显示', +'Send Notification'=>'发送邮件通知', +'Created Time'=>'建立时间', +'Modified Time'=>'修改时间', +'Activity Type'=>'活动类型', +'Description'=>'描述', +'Duration'=>'期间', +'Duration Minutes'=>'期间分钟', +'Location'=>'位置', +'No Time'=>'没有时间', +//Added for Send Reminder 4.2 release +'Send Reminder'=>'提醒通知', +'LBL_YES'=>'是', +'LBL_NO'=>'否', +'LBL_DAYS'=>'日', +'LBL_MINUTES'=>'分', +'LBL_HOURS'=>'时', +'LBL_BEFORE_EVENT'=>'时间前', +//Added for CustomView 4.2 Release +'Close'=>'关闭', +'Start Date'=>'开始日期', +'Type'=>'类型', +'End Date'=>'结束日期', +'Recurrence'=>'循环事件', +'Recurring Type'=>'循环类型', +//Activities - Notification Error +'LBL_NOTIFICATION_ERROR'=>'邮件错误:请检查您的发送邮件服务器设置,在设定 > 发送邮件服务器设置或是目前使用者的邮件设置', +// Mike Crowe Mod --------------------------------------------------------added for generic search +'LBL_GENERAL_INFORMATION'=>'一般信息', + +'LBL_EVENTTYPE'=>'事件类型', +'LBL_EVENTNAME'=>'事件名称', +'LBL_EVENTSTAT'=>'事件开始于', +'LBL_EVENTEDAT'=>'事件结束于', +'LBL_INVITE'=>'邀请', +'LBL_REPEAT'=>'重复', +'LBL_REMINDER'=>'提示', +'LBL_SENDREMINDER'=>'发送提示', +'LBL_NOTIFICATION'=>'通知', +'LBL_SENDNOTIFICATION'=>'发送通知', +'LBL_RMD_ON'=>'提醒', +'LBL_REPEATEVENT'=>'每个都重复一次', +'LBL_TIMEDATE'=>'时间和日期', +'LBL_HR'=>'时', +'LBL_MIN'=>'分', +'LBL_EVENT'=>'事件', +'Daily'=>'天', +'Weekly'=>'周', +'Monthly'=>'月', +'Yearly'=>'年', +'createdtime'=>'建立时间', +'modifiedtime'=>'修改时间', +'first'=>'第一个', +'last'=>'最后一个', +'High'=>'高', +'Medium'=>'中', +'Low'=>'低', +'LBL_SELECT'=>'选择', +'LBL_ALL_EVENTS_TODOS'=>'所有事件与工作', +'First'=>'第一笔', +'Last'=>'最后一笔', +'on'=>'于', +'day of the month'=>'日', +'Private'=>'私有', +'Public'=>'公共', + +//Added for existing Picklist entries + +'Planned'=>'已规划', +'Held'=>'保留', +'Not Held'=>'不保留', +'Completed'=>'完成', +'Deferred'=>'延期', +'Not Started'=>'未开始', +'In Progress'=>'处理中', +'Pending Input'=>'等待输入', +'LBL_REMAINDER_DAY'=>'天', +'LBL_REMAINDER_HRS'=>'小时', +'Call'=>'电话', +'Meeting'=>'会议', + +//added to send dates and time in calendar notification/invitation mail. + +'Start date and time'=>'开始日期和时间', +'End date and time'=>'结束日期和时间', +//this is for task +'End date'=>'结束日期', +'LBL_SET_DATE'=>'设置日期..', +'Recurrence'=>'再现', + +//added to send invitation mail Subject. +'INVITATION'=>'邀请', + +// Added/Updated for vtiger CRM 5.0.4 +'LBL_YEAR_BUTTON_TITLE'=>'Year[Alt+Y]', +'LBL_SELECT_CONTACT'=>'选择联系人', +'SHARED_EVENT_DEL_MSG'=>'用户没有允许删除这个纪录.', +//added to fix ticket#4525 +'LBL_CREATED'=>'新建', +'LBL_UPDATED'=>'更新', + +//Added after 5.0.4 GA +'LBL_BUSY'=>'忙碌', + +//Custom Fields support for Calendar +'LBL_CUSTOM_INFORMATION'=>'自定义信息', + +// Repeat Event support for Calendar +'LBL_UNTIL'=>'至', +'LBL_SET_DATE'=>'设置日期', + +'LBL_MINE'=>'我的', +'LBL_SUCCESS_CALENDAR_1' => '成功导入任务数 : ', +'LBL_SKIPPED_CALENDAR_1' => '忽略的任务数(一个字段或者多个字段丢失): ', +'LBL_SUCCESS_EVENTS_1' => '成功导入事件数 : ', +'LBL_SKIPPED_EVENTS_1' => '忽略的事件数(一个字段或者多个字段丢失): ', +'LBL_FINISHED'=>'完成', +'LBL_UNDO_LAST_IMPORT'=>'重做最后一次导入', +'LBL_LAST_IMPORT'=>'最后导入', +'LBL_LAST_IMPORT_UNDONE'=>'你的最后一次导入被重做', +'LBL_SUCCESS'=>'成功!', +'LBL_NO_IMPORT_TO_UNDO'=>'没有可重做的导入。', +'LBL_FAILURE'=>'完成!', +); + +?> diff --git a/oss/vtiger/trunk/modules/Calendar/new_calendar.php b/oss/vtiger/trunk/modules/Calendar/new_calendar.php new file mode 100644 index 00000000..afcf5490 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/new_calendar.php @@ -0,0 +1,92 @@ +activity_view == "This Year"){ + $mysel = 'year'; + }else if($current_user->activity_view == "This Month"){ + $mysel = 'month'; + }else if($current_user->activity_view == "This Week"){ + $mysel = 'week'; + }else{ + $mysel = 'day'; + } +} +/* fix given by dartagnanlaf END --integrated by Minnie */ +$date_data = array(); +if ( isset($_REQUEST['day'])) +{ + + $date_data['day'] = $_REQUEST['day']; +} + +if ( isset($_REQUEST['month'])) +{ + $date_data['month'] = $_REQUEST['month']; +} + +if ( isset($_REQUEST['week'])) +{ + $date_data['week'] = $_REQUEST['week']; +} + +if ( isset($_REQUEST['year'])) +{ + if ($_REQUEST['year'] > 2037 || $_REQUEST['year'] < 1970) + { + print("".$app_strings['LBL_CAL_LIMIT_MSG'].""); + exit; + } + $date_data['year'] = $_REQUEST['year']; +} + + +if(empty($date_data)) +{ + $data_value=date('Y-m-d H:i:s'); + preg_match('/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/',$data_value,$value); + $date_data = Array( + 'day'=>$value[3], + 'month'=>$value[2], + 'year'=>$value[1], + 'hour'=>$value[4], + 'min'=>$value[5], + ); + +} +$calendar_arr['calendar'] = new Calendar($mysel,$date_data); +if($current_user->hour_format != '') + $calendar_arr['calendar']->hour_format=$current_user->hour_format; +if ($viewBox == 'hourview' && ($mysel == 'day' || $mysel == 'week' || $mysel == 'month' || $mysel == 'year')) +{ + $calendar_arr['calendar']->add_Activities($current_user); +} +$calendar_arr['view'] = $mysel; +calendar_layout($calendar_arr,$viewBox,$subtab); +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/script.js b/oss/vtiger/trunk/modules/Calendar/script.js new file mode 100644 index 00000000..9a7bd799 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/script.js @@ -0,0 +1,1400 @@ +/********************************************************************************* + +** The contents of this file are subject to the vtiger CRM Public License Version 1.0 + * ("License"); You may not use this file except in compliance with the License + * The Original Code is: vtiger CRM Open Source + * The Initial Developer of the Original Code is vtiger. + * Portions created by vtiger are Copyright (C) vtiger. + * All Rights Reserved. + ********************************************************************************/ + +function DisableSharing() +{ + + x = document.SharedList.selected_id.length; + idstring = ""; + xx = 0; + if ( x == undefined) + { + + if (document.SharedList.selected_id.checked) + { + document.SharedList.idlist.value=document.SharedList.selected_id.value; + } + else + { + alert(alert_arr.SELECT_ATLEAST_ONE_USER); + return false; + } + } + else + { + for(i = 0; i < x ; i++) + { + if(document.SharedList.selected_id[i].checked) + { + idstring = document.SharedList.selected_id[i].value +";"+idstring + xx++ + } + } + if (xx != 0) + { + document.SharedList.idlist.value=idstring; + } + else + { + alert(alert_arr.SELECT_ATLEAST_ONE_USER); + return false; + } + } + if(confirm(alert_arr.DISABLE_SHARING_CONFIRMATION+xx+alert_arr.USERS)) + { + document.SharedList.action="index.php?module=Calendar&action=disable_sharing&return_module=Calendar&return_action=calendar_share"; + } + else + { + return false; + } +} + + + +function showhide(argg) +{ + var x=document.getElementById(argg).style; + if (x.display=="none") + { + x.display="block" + + } + else { + x.display="none" + } +} + + +function showhideRepeat(argg1,argg2) +{ + var x=document.getElementById(argg2).style; + var y=document.getElementById(argg1).checked; + + if (y) + { + x.display="block"; + } + else { + x.display="none"; + } + +} + + + +function gshow(argg1,type,startdate,enddate,starthr,startmin,startfmt,endhr,endmin,endfmt,viewOption,subtab) +{ + smin = parseInt(startmin,10); + smin = smin - (smin%5); + var y=document.getElementById(argg1).style; + + if(type != 'todo' && type!='') + { + for(var i=0;;i++){ + if( document.EditView.activitytype[i].value == type){ + document.EditView.activitytype[i].selected='yes'; + break; + } + } + + smin = _2digit(smin); + document.EditView.date_start.value = startdate; + document.EditView.starthr.value = starthr; + document.EditView.startmin.value = smin; + document.EditView.startfmt.value = startfmt; + document.EditView.viewOption.value = viewOption; + document.EditView.subtab.value = subtab; + calDuedatetime(type); + } + if(type == 'todo') + { + smin = _2digit(smin); + document.createTodo.task_date_start.value = startdate; + document.createTodo.task_due_date.value = enddate; + document.createTodo.starthr.value = starthr; + document.createTodo.startmin.value = smin; + document.createTodo.startfmt.value = startfmt; + document.createTodo.viewOption.value = viewOption; + document.createTodo.subtab.value = subtab; + } + if (y.display=="none") + { + y.display="block"; + } +} + +function rptoptDisp(Opt){ + var currOpt = Opt.options[Opt.selectedIndex].value; + if(currOpt == "Daily") + { + ghide('repeatWeekUI'); + ghide('repeatMonthUI'); + } + else if(currOpt == "Weekly") + { + if(document.getElementById('repeatWeekUI').style.display == "none"); + document.getElementById('repeatWeekUI').style.display = "block"; + ghide('repeatMonthUI'); + } + else if(currOpt == "Monthly") + { + ghide('repeatWeekUI'); + if(document.getElementById('repeatMonthUI').style.display == "none"); + document.getElementById('repeatMonthUI').style.display = "block"; + } + else if(currOpt == "Yearly") + { + ghide('repeatWeekUI'); + ghide('repeatMonthUI'); + } +} + +function Taskshow(argg1,type,startdate,starthr,startmin,startfmt) +{ + var y=document.getElementById(argg1).style; + if (y.display=="none") + { + document.EditView.date_start.value = startdate; + document.EditView.starthr.value = starthr; + document.EditView.startmin.value = startmin; + document.EditView.startfmt.value = startfmt; + y.display="block"; + } +} + +function ghide(argg2) +{ + var z=document.getElementById(argg2).style; + if (z.display=="block" ) + { + z.display="none" + + } +} + + function moveMe(arg1) { + var posx = 0; + var posy = 0; + var e=document.getElementById(arg1); + + if (!e) var e = window.event; + + if (e.pageX || e.pageY) + { + posx = e.pageX; + posy = e.pageY; + } + else if (e.clientX || e.clientY) + { + posx = e.clientX + document.body.scrollLeft; + posy = e.clientY + document.body.scrollTop; + } + } + +function switchClass(myModule,toStatus) { + var x=document.getElementById(myModule); + if($(x)) + { + if (toStatus=="on") { + x.className="dvtSelectedCell"; + } + if (toStatus=="off") { + x.className="dvtUnSelectedCell"; + } + } + +} + +function enableCalstarttime() +{ + if(document.SharingForm.sttime_check.checked == true) + document.SharingForm.start_hour.disabled = false; + else + document.SharingForm.start_hour.disabled = true; +} +function check_form() +{ + formSelectColumnString('inviteesid','selectedusers'); + if(trim(document.EditView.subject.value) == "") + { + alert(alert_arr.MISSING_EVENT_NAME); + document.EditView.subject.focus() + return false; + } + else + { + if(document.EditView.record.value != '') + { + document.EditView.mode.value = 'edit'; + } + else + { + document.EditView.mode.value = 'create'; + } + starthour = parseInt(document.EditView.starthr.value,10); + startmin = parseInt(document.EditView.startmin.value,10); + startformat = document.EditView.startfmt.value; + endhour = parseInt(document.EditView.endhr.value,10); + endmin = parseInt(document.EditView.endmin.value,10); + endformat = document.EditView.endfmt.value; + followupformat = document.EditView.followup_startfmt.value; + followuphour = parseInt(document.EditView.followup_starthr.value,10); + followupmin = parseInt(document.EditView.followup_startmin.value,10); + if(startformat != '') + { + if(startformat == 'pm') + { + if(starthour == 12) + starthour = 12; + else + starthour = starthour + 12; + } + else + { + if(starthour == 12) + starthour = 0; + else + starthour = starthour; + } + } + if(endformat != '') + { + if(endformat == 'pm') + { + if(endhour == 12) + endhour = 12; + else + endhour = endhour + 12; + } + else + { + if(endhour == 12) + endhour = 0; + else + endhour = endhour; + } + } + if(!dateValidate('date_start','Start date','OTH')) + { + return false; + } + if(!dateValidate('due_date','End date','OTH')) + { + return false; + } + if(dateComparison('due_date','End date','date_start','Start date','GE')) + { + var dateval1=getObj('date_start').value.replace(/^\s+/g, '').replace(/\s+$/g, ''); + var dateval2=getObj('due_date').value.replace(/^\s+/g, '').replace(/\s+$/g, ''); + var dateval3=getObj('followup_date').value.replace(/^\s+/g, '').replace(/\s+$/g, ''); + + var dateelements1=splitDateVal(dateval1) + var dateelements2=splitDateVal(dateval2) + var dateelements3=splitDateVal(dateval3) + + dd1=dateelements1[0] + mm1=dateelements1[1] + yyyy1=dateelements1[2] + + dd2=dateelements2[0] + mm2=dateelements2[1] + yyyy2=dateelements2[2] + + dd3=dateelements3[0] + mm3=dateelements3[1] + yyyy3=dateelements3[2] + + var date1=new Date() + var date2=new Date() + var date3=new Date() + + date1.setYear(yyyy1) + date1.setMonth(mm1-1) + date1.setDate(dd1) + date1.setHours(starthour) + date1.setMinutes(startmin) + + date2.setYear(yyyy2) + date2.setMonth(mm2-1) + date2.setDate(dd2) + date2.setHours(endhour) + date2.setMinutes(endmin) + + date3.setYear(yyyy3) + date3.setMonth(mm3-1) + date3.setDate(dd3) + + diff_ms = Math.abs(date2.getTime()-date1.getTime())/(1000*60); + hour = Math.floor(diff_ms/(60)); + minute = Math.floor(diff_ms % 60) + document.EditView.duration_hours.value = hour; + document.EditView.duration_minutes.value = minute; + + event_starthour = _2digit(starthour); + event_startmin = _2digit(startmin); + event_endhour = _2digit(endhour); + event_endmin = _2digit(endmin); + document.EditView.time_start.value = event_starthour+':'+event_startmin; + document.EditView.time_end.value = event_endhour+':'+event_endmin; + // Added for Aydin Kurt-Elli requirement START -by Minnie + if (document.EditView.followup.checked == true && document.getElementById('date_table_thirdtd').style.display == 'block') + { + if(!dateValidate('followup_date','Followup Date','OTH')) + { + return false; + } + if(followupformat != '') + { + if(followupformat == 'pm') + { + if(followuphour == 12) + followuphour = 12; + else + followuphour = followuphour + 12; + } + else + { + if(followuphour == 12) + followuphour = 0; + else + followuphour = followuphour; + } + } + + if ( compareDates(date3,'Followup Date',date2,'End Date','GE')) + { + if (date3 <= date2) + { + if((followuphour*60+followupmin) <= (endhour*60+endmin)) + { + alert(alert_arr.FOLLOWUPTIME_GREATER_THAN_STARTTIME); + document.EditView.followup_starthr.focus(); + return false; + } + } + } + else return false; + //modified to set followup end date depends on the event or todo. If it is Event, the difference between followup start date and end date is 1hr. If it is todo then difference is 5mins. + date3.setMinutes(followupmin); + date3.setHours(followuphour); + if(document.EditView.activitytype[0].checked == true) + { + date3.setMinutes(parseInt(date3.getMinutes(),10)+5); + } + if(document.EditView.activitytype[1].checked == true) + { + date3.setMinutes(parseInt(date3.getMinutes(),10)+60); + } + var tempdate = getdispDate(date3); + + followuphour = _2digit(followuphour); + followupmin = _2digit(followupmin); + followupendhour = _2digit(date3.getHours()); + followupendmin = _2digit(date3.getMinutes()); + document.EditView.followup_due_date.value = tempdate; + document.EditView.followup_time_start.value = followuphour+':'+followupmin; + document.EditView.followup_time_end.value = followupendhour+':'+followupendmin; + //end + } + // Added for Aydin Kurt-Elli requirement END -by Minnie --> + + //added to avoid db error while giving characters in the repeat "every n no of day in month" text box + if((getObj("recurringcheck")) && (document.EditView.recurringcheck.checked == true) && (document.EditView.recurringtype.value =="Monthly")) + { + if((document.EditView.repeatMonth[0].checked == true) && ((parseInt(parseFloat(document.EditView.repeatMonth_date.value))!=document.EditView.repeatMonth_date.value) || document.EditView.repeatMonth_date.value=='' || parseInt(document.EditView.repeatMonth_date.value)>'31' || document.EditView.repeatMonth_date.value<='0')) + { + alert(alert_arr.INVALID +' "'+document.EditView.repeatMonth_date.value+'" '); + document.EditView.repeatMonth_date.focus(); + return false; + } + } + //end + + + //added to check Start Date & Time,if Activity Status is Planned.//start + if(document.EditView.eventstatus.value == "Planned") + { + var chkdate=new Date() + chkdate.setMinutes(event_startmin) + chkdate.setHours(event_starthour) + chkdate.setYear(yyyy1) + chkdate.setMonth(mm1-1) + chkdate.setDate(dd1) + if(!comparestartdate(chkdate)) return false; + + } + + } + else + return false; + if(getObj("recurringcheck") && document.EditView.recurringcheck.checked == false) + { + document.EditView.recurringtype.value = '--None--'; + } + return true; + } +} + +function task_check_form() +{ + starthour = parseInt(document.createTodo.starthr.value,10); + startmin = parseInt(document.createTodo.startmin.value,10); + startformat = document.createTodo.startfmt.value; + if(startformat != '') + { + if(startformat == 'pm') + { + if(starthour == 12) + starthour = 12; + else + starthour = starthour + 12; + + } + else + { + if(starthour == 12) + starthour = 0; + else + starthour = starthour; + } + } + starthour = _2digit(starthour); + startmin = _2digit(startmin); + document.createTodo.task_time_start.value = starthour+':'+startmin; + if(document.createTodo.record.value != '') + { + document.createTodo.mode.value = 'edit'; + } + else + { + document.createTodo.mode.value = 'create'; + } + +} + + +function maintask_check_form() +{ + starthour = parseInt(document.EditView.starthr.value,10); + startmin = parseInt(document.EditView.startmin.value,10); + startformat = document.EditView.startfmt.value; + if(startformat != '') + { + if(startformat == 'pm') + { + if(starthour == 12) + starthour = 12; + else + starthour = starthour + 12; + } + else + { + if(starthour == 12) + starthour = 0; + else + starthour = starthour; + } + } + starthour = _2digit(starthour); + startmin = _2digit(startmin); + document.EditView.time_start.value = starthour+':'+startmin; +} + + +var moveupLinkObj,moveupDisabledObj,movedownLinkObj,movedownDisabledObj; + +function userEventSharing(selectedusrid,selcolid) +{ + formSelectColumnString(selectedusrid,selcolid); +} + + +function incUser(avail_users,sel_users) +{ + availListObj=getObj(avail_users) + selectedColumnsObj=getObj(sel_users) + var selectlength=selectedColumnsObj.length + var availlength=availListObj.length + + for (i=0;i= 0) + selectedColumnsObj.remove(selectedColumnsObj.options.selectedIndex) + } + +} + + +// function to delete activity related contact in calendar +var del_ids = new Array(); +function removeActContacts() +{ + var avail_contacts = getObj('parentid'); + // this block is to remove contacts and get deleted contact ids + if(avail_contacts.options.selectedIndex > -1) + { + for(m = 0; m < avail_contacts.options.length; m++) + { + if(avail_contacts.options[m].selected == true) + { + del_ids.push(avail_contacts.options[m].value); + avail_contacts.options[m] = null; + removeActContacts(); + } + } + } + document.EditView.deletecntlist.value = del_ids.join(";"); + + // this block is to get available id list + var avail_ids = new Array(); + for(n=0; n window.innerWidth ){ + leftSide = eval(leftSide) - eval(widthM); + tagName.style.left = leftSide + 'px'; + } + else + tagName.style.left= leftSide + 'px'; + tagName.style.top= topSide + 'px'; + tagName.style.display = 'block'; + tagName.style.visibility = "visible"; + if(type == 'event') + { + var heldstatus = "eventstatus=Held"; + var notheldstatus = "eventstatus=Not Held"; + var activity_mode = "Events"; + var complete = document.getElementById("complete"); + var pending = document.getElementById("pending"); + var postpone = document.getElementById("postpone"); + var actdelete = document.getElementById("actdelete"); + var changeowner = document.getElementById("changeowner"); + var OptionData = document.getElementById('view_Option').options[document.getElementById('view_Option').selectedIndex].value; + + } + if(type == 'todo') + { + var heldstatus = "status=Completed"; + var notheldstatus = "status=Deferred"; + var activity_mode = "Task"; + var complete = document.getElementById("taskcomplete"); + var pending = document.getElementById("taskpending"); + var postpone = document.getElementById("taskpostpone"); + var actdelete = document.getElementById("taskactdelete"); + var changeowner = document.getElementById("taskchangeowner"); + var OptionData = ''; + } + document.getElementById("idlist").value = id; + document.change_owner.hour.value = hour; + document.change_owner.day.value = day; + document.change_owner.view.value = view; + document.change_owner.month.value = month; + document.change_owner.year.value = year; + document.change_owner.subtab.value = type; + if(complete) complete.href="javascript:updateStatus("+id+",'"+heldstatus+"','"+view+"',"+hour+","+day+","+month+","+year+",'"+type+"')"; + if(pending) pending.href="javascript:updateStatus("+id+",'"+notheldstatus+"','"+view+"',"+hour+","+day+","+month+","+year+",'"+type+"')"; + + if(postpone) postpone.href="index.php?module=Calendar&action=EditView&record="+id+"&return_action=index&activity_mode="+activity_mode+"&view="+view+"&hour="+hour+"&day="+day+"&month="+month+"&year="+year+"&viewOption="+OptionData+"&subtab="+type+"&maintab=Calendar"; + + if(actdelete) actdelete.href="javascript:delActivity("+id+",'"+view+"',"+hour+","+day+","+month+","+year+",'"+type+"')"; + + if(changeowner) changeowner.href="javascript:dispLayer('act_changeowner');"; + +} + +function dispLayer(lay) +{ + var tagName = document.getElementById(lay); + tagName.style.visibility = 'visible'; + tagName.style.display = 'block'; +} + +//check whether user form selected or group form selected +function checkgroup() +{ + if($("group_checkbox").checked) + { + document.change_owner.lead_group_owner.style.display = "block"; + document.change_owner.lead_owner.style.display = "none"; + } + else + { + document.change_owner.lead_group_owner.style.display = "none"; + document.change_owner.lead_owner.style.display = "block"; + } +} + +function calendarChangeOwner() +{ + var idlist = document.change_owner.idlist.value; + var view = document.change_owner.view.value; + var day = document.change_owner.day.value; + var month = document.change_owner.month.value; + var year = document.change_owner.year.value; + var hour = document.change_owner.hour.value; + var subtab = document.change_owner.subtab.value; + + //var checked = document.change_owner.user_lead_owner[0].checked; + if($("user_checkbox").checked) + { + var user_id = document.getElementById('lead_owner').options[document.getElementById('lead_owner').options.selectedIndex].value; + var url = 'module=Users&action=updateLeadDBStatus&return_module=Calendar&return_action=ActivityAjax&owner_id='+user_id+'&idlist='+idlist+'&view='+view+'&hour='+hour+'&day='+day+'&month='+month+'&year='+year+'&type=change_owner&owner_type=User'; + } + else + { + var group_id = document.getElementById('lead_group_owner').options[document.getElementById('lead_group_owner').options.selectedIndex].value; + var url = 'module=Users&action=updateLeadDBStatus&return_module=Calendar&return_action=ActivityAjax&owner_id='+group_id+'&idlist='+idlist+'&view='+view+'&hour='+hour+'&day='+day+'&month='+month+'&year='+year+'&type=change_owner&owner_type=Group'; + } + + if(subtab == 'event') + { + var OptionData = $('view_Option').options[$('view_Option').selectedIndex].value; + var eventurl = url+'&viewOption='+OptionData+'&subtab=event&ajax=true'; + + new Ajax.Request( + 'index.php', + {queue: {position: 'end', scope: 'command'}, + method: 'post', + postBody: eventurl, + onComplete: function(response) { + if(OptionData == 'listview') + { + result = response.responseText.split('####'); + $("total_activities").innerHTML = result[1]; + $("listView").innerHTML=result[0]; + document.EventViewOption.action.value = "index"; + window.document.EventViewOption.submit(); + } + if(OptionData == 'hourview') + { + result = response.responseText.split('####'); + $("total_activities").innerHTML = result[1]; + $("hrView").innerHTML=result[0]; + document.EventViewOption.action.value = "index"; + window.document.EventViewOption.submit(); + } + } + } + ); + } + if(subtab == 'todo') + { + + var todourl = url+'&subtab=todo&ajax=true'; + new Ajax.Request( + 'index.php', + {queue: {position: 'end', scope: 'command'}, + method: 'post', + postBody: todourl, + onComplete: function(response) { + result = response.responseText.split('####'); + $("total_activities").innerHTML = result[1]; + $("mnuTab2").innerHTML=result[0]; + } + } + ); + } +} + +function delActivity(id,view,hour,day,month,year,subtab) +{ + if(subtab == 'event') + { + var OptionData = $('view_Option').options[$('view_Option').selectedIndex].value; + new Ajax.Request( + 'index.php', + {queue: {position: 'end', scope: 'command'}, + method: 'post', + postBody: 'module=Users&action=massdelete&return_module=Calendar&return_action=ActivityAjax&idlist='+id+'&view='+view+'&hour='+hour+'&day='+day+'&month='+month+'&year='+year+'&type=activity_delete&viewOption='+OptionData+'&subtab=event&ajax=true', + onComplete: function(response) { + if(OptionData == 'listview') + { + result = response.responseText.split('####'); + $("total_activities").innerHTML = result[1]; + $("listView").innerHTML=result[0]; + } + if(OptionData == 'hourview') + { + result = response.responseText.split('####'); + $("total_activities").innerHTML = result[1]; + $("hrView").innerHTML=result[0]; + } + } + } + ); + } + if(subtab == 'todo') + { + new Ajax.Request( + 'index.php', + {queue: {position: 'end', scope: 'command'}, + method: 'post', + postBody: 'module=Users&action=massdelete&return_module=Calendar&return_action=ActivityAjax&idlist='+id+'&view='+view+'&hour='+hour+'&day='+day+'&month='+month+'&year='+year+'&type=activity_delete&subtab=todo&ajax=true', + onComplete: function(response) { + result = response.responseText.split('####'); + $("total_activities").innerHTML = result[1]; + $("mnuTab2").innerHTML=result[0]; + } + } + ); + } +} + + +/* +* javascript function to display the div tag +* @param divId :: div tag ID +*/ +function cal_show(divId) + +{ + + var id = document.getElementById(divId); + + id.style.visibility = 'visible'; + +} + +function fnAssignTo(){ + var option_Box = document.getElementById('parent_type'); + var option_select = option_Box.options[option_Box.selectedIndex].value; + if(option_select == "Leads" || option_select == "Leads&action=Popup") + { + document.getElementById('leadLay').style.visibility = 'visible'; + } + else if(option_select == "Accounts" || option_select == "Accounts&action=Popup") + { + document.getElementById('leadLay').style.visibility = 'visible'; + } + else if(option_select == "Potentials" || option_select == "Potentials&action=Popup") + { + document.getElementById('leadLay').style.visibility = 'visible'; + } + else if(option_select == "Quotes&action=Popup" || option_select == "Quotes&action=Popup") + { + document.getElementById('leadLay').style.visibility = 'visible'; + } + else if(option_select == "PurchaseOrder" || option_select == "PurchaseOrder&action=Popup") + { + document.getElementById('leadLay').style.visibility = 'visible'; + } + else if(option_select == "SalesOrder" || option_select == "SalesOrder&action=Popup") + { + document.getElementById('leadLay').style.visibility = 'visible'; + } + else if(option_select == "Invoice" || option_select == "Invoice&action=Popup") + { + document.getElementById('leadLay').style.visibility = 'visible'; + } + else if(option_select == "Campaigns" || option_select == "Campaigns&action=Popup") + { + document.getElementById('leadLay').style.visibility = 'visible'; + } + else{ + document.getElementById('leadLay').style.visibility = 'hidden'; + } + } + +function fnShowPopup(){ + document.getElementById('popupLay').style.display = 'block'; +} + +function fnHidePopup(){ + document.getElementById('popupLay').style.display = 'none'; +} + +function getValidationarr(id,activity_mode,opmode,subtab,viewOption) +{ + new Ajax.Request( + 'index.php', + {queue: {position: 'end', scope: 'command'}, + method: 'post', + postBody: 'module=Calendar&action=ActivityAjax&record='+id+'&activity_mode='+activity_mode+'&ajax=true&type=view&file=DetailView', + onComplete: function(response) { + $("dataArray").innerHTML=response.responseText; + setFieldvalues(opmode,subtab,viewOption); + } + } + ); + +} + +function setFieldvalues(opmode,subtab,viewOption) +{ + var st = document.getElementById('activity_cont'); + eval(st.innerHTML); + if(activity_type == 'Events') + { + document.EditView.viewOption.value = viewOption; + document.EditView.subtab.value = subtab; + for(x=0;x is a contact id + ltext ==> is a contact name +**/ +function addOption(lvalue,ltext) +{ + var optObj = document.createElement('OPTION') + if (browser_ie) optObj.innerText = ltext; + else if(browser_nn4 || browser_nn6) optObj.text = ltext; + else optObj.text = ltext; + optObj.value = lvalue; + document.getElementById('parentid').appendChild(optObj); +} + +function getdispDate(tempDate) +{ + var datefmt = document.EditView.dateformat.value; + var dd = _2digit(parseInt(tempDate.getDate(),10)); + var mm = _2digit(parseInt(tempDate.getMonth(),10)+1); + var yy = tempDate.getFullYear(); + if(datefmt == '%d-%m-%Y') return dd+'-'+mm+'-'+yy; + else if(datefmt == '%m-%d-%Y') return mm+'-'+dd+'-'+yy; + else return yy+'-'+mm+'-'+dd; +} diff --git a/oss/vtiger/trunk/modules/Calendar/updateCalendarSharing.php b/oss/vtiger/trunk/modules/Calendar/updateCalendarSharing.php new file mode 100644 index 00000000..a1c09e71 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/updateCalendarSharing.php @@ -0,0 +1,45 @@ +pquery($delquery, array($_REQUEST["current_userid"])); + +$selectedid = $_REQUEST['shar_userid']; +$sharedid = explode (";",$selectedid); +if(isset($sharedid) && $sharedid != null) +{ + foreach($sharedid as $sid) + { + if($sid != '') + { + $sql = "insert into vtiger_sharedcalendar values (?,?)"; + $adb->pquery($sql, array($_REQUEST["current_userid"], $sid)); + } + } +} +if(isset($_REQUEST['start_hour']) && $_REQUEST['start_hour'] != '') +{ + $sql = "update vtiger_users set start_hour=? where id=?"; + $adb->pquery($sql, array($_REQUEST['start_hour'], $current_user->id)); +} + +$sql = "update vtiger_users set hour_format=? where id=?"; +$adb->pquery($sql, array($hour_format, $current_user->id)); +RecalculateSharingRules(); +header("Location: index.php?action=index&module=Calendar&view=".vtlib_purify($_REQUEST['view'])."&hour=".vtlib_purify($_REQUEST['hour'])."&day=".vtlib_purify($_REQUEST['day'])."&month=".vtlib_purify($_REQUEST['month'])."&year=".vtlib_purify($_REQUEST['year'])."&viewOption=".vtlib_purify($_REQUEST['viewOption'])."&subtab=".vtlib_purify($_REQUEST['subtab'])."&parenttab=".getParentTab()); + +?> \ No newline at end of file diff --git a/oss/vtiger/trunk/modules/Calendar/updateRelations.php b/oss/vtiger/trunk/modules/Calendar/updateRelations.php new file mode 100644 index 00000000..b6e17de7 --- /dev/null +++ b/oss/vtiger/trunk/modules/Calendar/updateRelations.php @@ -0,0 +1,64 @@ +pquery($sql, array($id, $_REQUEST["parentid"])); + } + } + header("Location: index.php?action=CallRelatedList&module=Calendar&activity_mode=Events&record=".$record); + +} +elseif(isset($_REQUEST['entityid']) && $_REQUEST['entityid'] != '' && $_REQUEST['destination_module'] == 'Contacts') +{ + $record = vtlib_purify($_REQUEST["parentid"]); + $sql = "insert into vtiger_cntactivityrel values (?,?)"; + $adb->pquery($sql, array($_REQUEST["entityid"], $_REQUEST["parentid"])); + header("Location: index.php?action=DetailView&module=Calendar&activity_mode=Events&record=".$record); +} + +//This if for adding the vtiger_users +if(isset($_REQUEST['idlist']) && $_REQUEST['idlist'] != '' && $_REQUEST['destination_module'] == 'Users') +{ + //split the string and store in an array + $storearray = explode (";",$idlist); + foreach($storearray as $id) + { + if($id != '') + { + $record = vtlib_purify($_REQUEST['parentid']); + $sql = "insert into vtiger_salesmanactivityrel values (?,?)"; + $adb->pquery($sql, array($id, $_REQUEST["parentid"])); + } + } + header("Location: index.php?action=DetailView&module=Calendar&activity_mode=Events&record=".$record); +} +elseif(isset($_REQUEST['entityid']) && $_REQUEST['entityid'] != '' && $_REQUEST['destination_module'] == 'Users') +{ + $record = vtlib_purify($_REQUEST['parentid']); + $sql = "insert into vtiger_salesmanactivityrel values (?,?)"; + $adb->pquery($sql, array($_REQUEST["entityid"], $_REQUEST["parentid"])); + header("Location: index.php?action=DetailView&module=Calendar&activity_mode=Events&record=".$record); + +} + +?> \ No newline at end of file