name"; } function create_list_query($order_by, $where, $show_deleted = 0) { $custom_join = $this->custom_fields->getJOIN(); $query = "SELECT "; $query .= " $this->table_name.*, contacts.first_name, contacts.last_name, contacts.assigned_user_id contact_name_owner, users.user_name as assigned_user_name"; if($custom_join){ $query .= $custom_join['select']; } $query .= " FROM ecmtasks "; $query .= "LEFT JOIN contacts ON ecmtasks.contact_id=contacts.id"; $query .= " LEFT JOIN users ON ecmtasks.assigned_user_id=users.id "; if($custom_join){ $query .= $custom_join['join']; } $where_auto = '1=1'; if($show_deleted == 0){ $where_auto = " ecmtasks.deleted=0 AND ( contacts.deleted IS NULL OR contacts.deleted=0) "; }else if($show_deleted == 1){ $where_auto = "$this->table_name.deleted=1"; } //GROUP BY ecmtasks.id"; if($where != "") $query .= "where $where AND ".$where_auto; else $query .= "where ".$where_auto; if($order_by != "") $query .= " ORDER BY ". $this->process_order_by($order_by, null); else $query .= " ORDER BY ecmtasks.name"; return $query; } function create_export_query(&$order_by, &$where) { $contact_required = ereg("contacts", $where); $custom_join = $this->custom_fields->getJOIN(true, true); if($contact_required) { $query = "SELECT ecmtasks.*, contacts.first_name, contacts.last_name"; if($custom_join){ $query .= $custom_join['select']; } $query .= " FROM contacts, ecmtasks "; $where_auto = "ecmtasks.contact_id = contacts.id AND ecmtasks.deleted=0 AND contacts.deleted=0"; } else { $query = 'SELECT ecmtasks.*'; if($custom_join){ $query .= $custom_join['select']; } $query .= ' FROM ecmtasks '; $where_auto = "ecmtasks.deleted=0"; } if($custom_join){ $query .= $custom_join['join']; } if($where != "") $query .= "where $where AND ".$where_auto; else $query .= "where ".$where_auto; if($order_by != "") $query .= " ORDER BY ". $this->process_order_by($order_by, null); else $query .= " ORDER BY ecmtasks.name"; return $query; } function fill_in_additional_list_fields() { //echo $this->assigned_user_id2.'lol'; //global $app_strings, $focus; //if(!empty($this->field_defs['created_by'])) { //$this->created_by_name = get_assigned_user_name($this->field_defs['created_by']); //print_r($this); //echo $focus->created_by; //$this->created_by_name = $this->field_defs['created_by']; //}/* $query="SELECT assigned_user_id2 FROM ecmtasks WHERE id='$this->id'"; $result = $this->db->query($query,true," Error filling in additional detail fields: "); $row = $this->db->fetchByAssoc($result); if(!empty($row['assigned_user_id2'])) { $this->assigned_user_id2= $row['assigned_user_id2']; $query2="SELECT first_name,last_name FROM users WHERE id='$this->assigned_user_id2'"; $result2 = $this->db->query($query2,true," Error filling in additional detail fields: "); $row2 = $this->db->fetchByAssoc($result2); if(!empty($row2['last_name'])){ $this->assigned_user_name2=$row2['first_name'].' '.$row2['last_name']; } } else { $this->assigned_user_name2= null; } } function fill_in_additional_detail_fields() { parent::fill_in_additional_detail_fields(); global $app_strings; if (isset($this->contact_id)) { require_once("modules/Contacts/Contact.php"); $contact = new Contact(); $contact->retrieve($this->contact_id); if($contact->id != "") { $this->contact_name = $contact->full_name; $this->contact_name_owner = $contact->assigned_user_id; $this->contact_name_mod = 'Contacts'; $this->contact_phone = $contact->phone_work; $this->contact_email = $contact->emailAddress->getPrimaryAddress($contact); } else { $this->contact_name_mod = ''; $this->contact_name_owner = ''; $this->contact_name=''; $this->contact_email = ''; $this->contact_id=''; } } $this->fill_in_additional_parent_fields(); } function fill_in_additional_parent_fields() { $this->parent_name = ''; global $app_strings, $beanFiles, $beanList; if ( ! isset($beanList[$this->parent_type])) { $this->parent_name = ''; return; } $beanType = $beanList[$this->parent_type]; require_once($beanFiles[$beanType]); $parent = new $beanType(); if (is_subclass_of($parent, 'Person')) { $query = "SELECT first_name, last_name, assigned_user_id parent_name_owner from $parent->table_name where id = '$this->parent_id'"; } else { $query = "SELECT name "; if(isset($parent->field_defs['assigned_user_id'])){ $query .= " , assigned_user_id parent_name_owner "; }else{ $query .= " , created_by parent_name_owner "; } $query .= " from $parent->table_name where id = '$this->parent_id'"; } $result = $this->db->query($query,true," Error filling in additional detail fields: "); // Get the id and the name. $row = $this->db->fetchByAssoc($result); if ($row && !empty($row['parent_name_owner'])){ $this->parent_name_owner = $row['parent_name_owner']; $this->parent_name_mod = $this->parent_type; } if (is_subclass_of($parent, 'Person') and $row != null) { $this->parent_name = ''; if ($row['first_name'] != '') $this->parent_name .= stripslashes($row['first_name']). ' '; if ($row['last_name'] != '') $this->parent_name .= stripslashes($row['last_name']); } elseif($row != null) { $this->parent_name = stripslashes($row['name']); } else { $this->parent_name = ''; } } function get_list_view_data(){ global $action, $currentModule, $focus, $current_module_strings, $app_list_strings, $image_path, $timedate; $today = $timedate->handle_offset(date($GLOBALS['timedate']->get_db_date_time_format(), time()), $timedate->dbDayFormat, true); $ecmtask_fields = $this->get_list_view_array(); $ecmtask_fields['TIME_DUE'] = $timedate->to_display_time($timedate->to_db_time($ecmtask_fields['DATE_DUE'])); $ecmtask_fields['DATE_DUE'] = $timedate->to_display_date($timedate->to_db($ecmtask_fields['DATE_DUE'])); $date_due = $ecmtask_fields['DATE_DUE']; if (!empty($this->priority)) $ecmtask_fields['PRIORITY'] = $app_list_strings['ecmtask_priority_dom'][$this->priority]; if (isset($this->parent_type)) $ecmtask_fields['PARENT_MODULE'] = $this->parent_type; if ($this->status != "Completed" && $this->status != "Deferred" ) { $ecmtask_fields['SET_COMPLETE'] = "".get_image($image_path."close_inline","alt='Close' border='0'").""; } $dd = $timedate->to_db_date($date_due, false); if ($dd < $today){ $ecmtask_fields['DATE_DUE']= "".$date_due.""; }else if( $dd == $today ){ $ecmtask_fields['DATE_DUE'] = "".$date_due.""; }else{ $ecmtask_fields['DATE_DUE'] = "".$date_due.""; } require_once('include/generic/SugarWidgets/SugarWidgetSubPanelAdditionalDetailsLink.php'); $arr = array(); $swspadl = new SugarWidgetSubPanelAdditionalDetailsLink($arr); $arr = array( 'module' => 'EcmTasks', 'fields' => array ( 'ID' => $this->id ) ); $ecmtask_fields['AD'] = $swspadl->displayList($arr); $ecmtask_fields['AD2']='Zadanie'; $ecmtask_fields['CONTACT_NAME']= $this->contact_name; //return_name($ecmtask_fields,"FIRST_NAME","LAST_NAME"); $ecmtask_fields['TITLE'] = ''; if (!empty($ecmtask_fields['CONTACT_NAME'])) { $ecmtask_fields['TITLE'] .= $current_module_strings['LBL_LIST_CONTACT'].": ".$ecmtask_fields['CONTACT_NAME']; } if (!empty($this->parent_name)) { $ecmtask_fields['TITLE'] .= "\n".$app_list_strings['record_type_display_notes'][$this->parent_type].": ".$this->parent_name; $ecmtask_fields['PARENT_NAME']=$this->parent_name; } $user = new User(); $this->retrieve($this->id); $user->retrieve($this->created_by); $ecmtask_fields['CREATED_BY_NAME'] = $user->full_name; unset($user); $ecmtask_fields['ASSIGNED_USER_NAME'] = ''.$ecmtask_fields['ASSIGNED_USER_NAME'].'
'.$ecmtask_fields['ASSIGNED_USER_NAME2'].''; return $ecmtask_fields; } function set_notification_body($xtpl, $ecmtask) { global $app_list_strings; global $timedate; $notifyUser = $ecmtask->current_notify_user; $prefDate = User::getUserDateTimePreferences($notifyUser); $xtpl->assign("TASK_SUBJECT", $ecmtask->name); //MFH #13507 $xtpl->assign("TASK_PRIORITY", (isset($ecmtask->priority)?$app_list_strings['ecmtask_priority_dom'][$ecmtask->priority]:"")); $xtpl->assign("TASK_DUEDATE", $timedate->to_display_date_time($ecmtask->date_due . " " . $ecmtask->time_due,true,true,$notifyUser)." ".$prefDate['userGmt']); $xtpl->assign("TASK_STATUS", (isset($ecmtask->status)?$app_list_strings['ecmtask_status_dom'][$ecmtask->status]:"")); $xtpl->assign("TASK_DESCRIPTION", $ecmtask->description); return $xtpl; } function bean_implements($interface){ switch($interface){ case 'ACL':return true; } return false; } function listviewACLHelper(){ $array_assign = parent::listviewACLHelper(); $is_owner = false; if(!empty($this->parent_name)){ if(!empty($this->parent_name_owner)){ global $current_user; $is_owner = $current_user->id == $this->parent_name_owner; } } if(!ACLController::moduleSupportsACL($this->parent_type) || ACLController::checkAccess($this->parent_type, 'view', $is_owner)){ $array_assign['PARENT'] = 'a'; }else{ $array_assign['PARENT'] = 'span'; } $is_owner = false; if(!empty($this->contact_name)){ if(!empty($this->contact_name_owner)){ global $current_user; $is_owner = $current_user->id == $this->contact_name_owner; } } if( ACLController::checkAccess('Contacts', 'view', $is_owner)){ $array_assign['CONTACT'] = 'a'; }else{ $array_assign['CONTACT'] = 'span'; } return $array_assign; } // //Before /* function save($check_notify = FALSE) { if (empty($this->status) ) { $mod_strings = return_module_language($GLOBALS['current_language'], $this->module_dir); $this->status = $mod_strings['LBL_DEFAULT_STATUS']; } return parent::save($check_notify); } */ //After function save($check_notify = FALSE){ global $current_user; if (empty($this->status) ) { $mod_strings = return_module_language($GLOBALS['current_language'], $this->module_dir); $this->status = $mod_strings['LBL_DEFAULT_STATUS']; } if(is_array($this->fetched_row)) { if($this->fetched_row['status'] != $this->status) { if($this->fetched_row['status'] == "In Progress" && $this->status == "In Review") { require_once('modules/Users/User.php'); $user = new User(); $user->retrieve($this->created_by); $this->send_to_user($user); } if($this->fetched_row['status'] == "In Review" && $this->status == "Completed" && $current_user->id != $this->assigned_user_id) { require_once('modules/Users/User.php'); $user = new User(); $user->retrieve($this->assigned_user_id); $this->send_to_user($user); } } } // echo 'ds: '.$this->date_start.'

'; //die("nie zapisuj"); // if ($this->assigned_user_id == '2e72f487-d92b-954e-f50c-528b10ce81c9' ) { if($this->google_calendar_ecmtask==null){ $this->google_calendar_ecmtask = $this->addGoogleCalendarEcmTask();} // } $return_id = parent::save($check_notify); //add event to google calendar return $return_id; } function send_to_user($notify_user) { require_once("modules/Administration/Administration.php"); $admin = new Administration(); $admin->retrieveSettings(); $sendNotifications = false; if ($admin->settings['notify_on']) { $GLOBALS['log']->info("Notifications: user assignment has changed, checking if user receives notifications"); $sendNotifications = true; } elseif(isset($_REQUEST['send_invites']) && $_REQUEST['send_invites'] == 1) { // cn: bug 5795 Send Invites failing for Contacts $sendNotifications = true; } else { $GLOBALS['log']->info("Notifications: not sending e-mail, notify_on is set to OFF"); } if($sendNotifications == true) $this->send_assignment_notifications__($notify_user, $admin); } function send_assignment_notifications__($notify_user, $admin) { global $current_user; if(($this->object_name == 'Meeting' || $this->object_name == 'Call') || $notify_user->receive_notifications) { $sendToEmail = $notify_user->emailAddress->getPrimaryAddress($notify_user); if(empty($sendToEmail)) { $GLOBALS['log']->warn("Notifications: no e-mail address set for user {$notify_user->user_name}, cancelling send"); } else { $notify_mail = $this->create_notification_email__($notify_user); $notify_mail->setMailerForSystem(); if(empty($admin->settings['notify_send_from_assigning_user'])) { $notify_mail->From = $admin->settings['notify_fromaddress']; $notify_mail->FromName = (empty($admin->settings['notify_fromname'])) ? "" : $admin->settings['notify_fromname']; } else { // Send notifications from the current user's e-mail (ifset) $fromAddress = $current_user->emailAddress->getReplyToAddress($current_user); $fromAddress = !empty($fromAddress) ? $fromAddress : $admin->settings['notify_fromaddress']; $notify_mail->From = $fromAddress; $from_name = !empty($admin->settings['notify_fromname']) ? $admin->settings['notify_fromname'] : ""; if($current_user->getPreference('mail_fromname') != '') { $from_name = $current_user->getPreference('mail_fromname'); } $notify_mail->FromName = $from_name; } if(!$notify_mail->Send()) { $GLOBALS['log']->warn("Notifications: error sending e-mail (method: {$notify_mail->Mailer}), (error: {$notify_mail->ErrorInfo})"); } else { $GLOBALS['log']->info("Notifications: e-mail successfully sent"); } } } } function create_notification_email__($notify_user) { global $sugar_version; global $sugar_config; global $app_list_strings; global $current_user; global $locale; require_once("XTemplate/xtpl.php"); require_once("include/SugarPHPMailer.php"); $notify_address = $notify_user->emailAddress->getPrimaryAddress($notify_user); $notify_name = $notify_user->full_name; $GLOBALS['log']->debug("Notifications: user has e-mail defined"); $notify_mail = new SugarPHPMailer(); $notify_mail->AddAddress($notify_address, $notify_name); if(empty($_SESSION['authenticated_user_language'])) { $current_language = $sugar_config['default_language']; } else { $current_language = $_SESSION['authenticated_user_language']; } $xtpl = new XTemplate("include/language/{$current_language}.notify_template.html"); $template_name = 'EcmTask'; $this->current_notify_user = $notify_user; if(in_array('set_notification_body', get_class_methods($this))) { $xtpl = $this->set_notification_body($xtpl, $this); } else { $xtpl->assign("OBJECT", $this->object_name); $template_name = "Default"; } $xtpl->assign("ASSIGNED_USER", $this->new_assigned_user_name); $xtpl->assign("ASSIGNER", $current_user->name); $port = ''; if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) { $port = $_SERVER['SERVER_PORT']; } $httpHost = $_SERVER['HTTP_HOST']; if($colon = strpos($httpHost, ':')) { $httpHost = substr($httpHost, 0, $colon); } $parsedSiteUrl = parse_url($sugar_config['site_url']); $host = ($parsedSiteUrl['host'] != $httpHost) ? $httpHost : $parsedSiteUrl['host']; if(!isset($parsedSiteUrl['port'])) { $parsedSiteUrl['port'] = 80; } $port = ($parsedSiteUrl['port'] != 80) ? ":".$parsedSiteUrl['port'] : ''; $path = !empty($parsedSiteUrl['path']) ? $parsedSiteUrl['path'] : ""; $cleanUrl = "{$parsedSiteUrl['scheme']}://{$host}{$port}{$path}"; if(eregi("localhost",$cleanUrl))$cleanUrl=str_replace("localhost","localhost:8080/vserver/e5crm.more7.com/www",$cleanUrl); $xtpl->assign("URL", $cleanUrl."/index.php?module={$this->module_dir}&action=DetailView&record={$this->id}"); $xtpl->assign("SUGAR", "Sugar v{$sugar_version}"); $xtpl->assign("WHO_CHANGE", $current_user->full_name); $xtpl->parse($template_name); $xtpl->parse($template_name . "_Subject"); $notify_mail->Body = from_html(trim($xtpl->text($template_name))); $notify_mail->Subject = from_html($xtpl->text($template_name . "_Subject")); // cn: bug 8568 encode notify email in User's outbound email encoding $notify_mail->prepForOutbound(); return $notify_mail; } function addGoogleCalendarEcmTask() { //die('test'); global $current_user; require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); Zend_Loader::loadClass('Zend_Http_Client'); // connect to service $p = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT google_login,CAST(AES_DECRYPT(google_password, 'jakistamhash123') as CHAR) AS google_password,google_calendar_name FROM users WHERE id='".$this->assigned_user_id."'")); if($p['google_login']!='' && $p['google_password']!=''){ $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; $user = $p['google_login']; $pass = $p['google_password']; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal); $gcal = new Zend_Gdata_Calendar($client); //date $start_time = array(); $start_time[] = intval(substr($this->date_start, 11,2)); $start_time[] = intval(substr($this->date_start, 14,2)); $start_time[] = intval(substr($this->date_start, 0,2)); $start_time[] = intval(substr($this->date_start, 3,2)); $start_time[] = intval(substr($this->date_start, 6,4)); $start = date(DATE_ATOM, mktime($start_time[0],$start_time[1],0,$start_time[2],$start_time[3],$start_time[4])); $date = new DateTime($this->date_start); $a='T'; $rok=$date->format('Y-m-d'); $czas=$date->format('H:i:s'); echo $start=$rok.'T'.$czas.'+01:00'; $end_time = array(); $end_time[] = intval(substr($this->date_due, 11,2)); $end_time[] = intval(substr($this->date_due, 14,2)); $end_time[] = intval(substr($this->date_due, 0,2)); $end_time[] = intval(substr($this->date_due, 3,2)); $end_time[] = intval(substr($this->date_due, 6,4)); $end = date(DATE_ATOM, mktime($end_time[0],$end_time[1],0,$end_time[2],$end_time[3],$end_time[4])); $date = new DateTime($this->date_due); $a='T'; $rok=$date->format('Y-m-d'); $czas=$date->format('H:i:s'); echo $end=$rok.'T'.$czas.'+01:00'; //create description $description = $this->description; if ($this->parent_id && $this->parent_id!='') { //get parent informations $p = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT * FROM ".strtolower($this->parent_type)." WHERE id='".$this->parent_id."'")); global $app_strings; $description.=" ".$app_strings['LBL_'.strtoupper($this->parent_type)].': '.$p['name']; //create where $where = $p['billing_address_city'].', '.$p['billing_address_street']; } // die('test'); // save to server try { $event = $gcal->newEventEntry(); $event->content =$gcal->newContent($description); $event->title = $gcal->newTitle($this->name); $when = $gcal->newWhen(); $when->startTime = $start; $when->endTime = $end; //$query->setVisibility('private'); $event->when = array($when); $event->where = array($gcal->newWhere($where)); $new_ecmtask = $gcal->insertEvent($event); $google_calendar_ecmtask = $new_ecmtask->getEditLink()->href; //save gct_id //$GLOBALS['db'] -> query("UPDATE ecmtasks SET google_calendar_ecmtask='".$google_calendar_ecmtask."' WHERE id='".$this->id."'"); } catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getResponse(); } catch (Exception $e) { echo "Error:" . $e->getResponse(); } //die($new_ecmtask.' '.$google_calendar_ecmtask); return $google_calendar_ecmtask; } } //
} ?>