Exemplo n.º 1
0
 public static function submit_task($values, $mode)
 {
     $me = CRM_ContactsCommon::get_my_record();
     switch ($mode) {
         case 'display':
             $values['title'] = __('Follow-up') . ': ' . $values['title'];
             $values['status'] = 0;
             $values['deadline'] = date('Y-m-d', strtotime('+1 day'));
             $ret = array();
             $cus = reset($values['customers']);
             if (ModuleManager::is_installed('CRM/Meeting') >= 0) {
                 $ret['new']['event'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Meeting')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('crm_meeting', array('title' => $values['title'], 'permission' => $values['permission'], 'priority' => $values['priority'], 'description' => $values['description'], 'date' => date('Y-m-d'), 'time' => date('H:i:s'), 'duration' => 3600, 'employees' => $values['employees'], 'customers' => $values['customers'], 'status' => 0), 'none', false) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Calendar', 'icon-small.png') . '" /></a>';
             }
             $ret['new']['task'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Task')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('task', $values) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Tasks', 'icon-small.png') . '" /></a>';
             if (ModuleManager::is_installed('CRM/PhoneCall') >= 0) {
                 $ret['new']['phonecall'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Phonecall')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('phonecall', array('subject' => $values['title'], 'permission' => $values['permission'], 'priority' => $values['priority'], 'description' => $values['description'], 'date_and_time' => date('Y-m-d H:i:s'), 'employees' => $values['employees'], 'customer' => $cus, 'status' => 0), 'none', false) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_PhoneCall', 'icon-small.png') . '" /></a>';
             }
             $ret['new']['note'] = Utils_RecordBrowser::$rb_obj->add_note_button('task/' . $values['id']);
             return $ret;
         case 'adding':
             $values['deadline_time'] = strtotime(date('Y-m-d') . ' 23:59:59');
             $values['permission'] = Base_User_SettingsCommon::get('CRM_Common', 'default_record_permission');
             break;
         case 'add':
             break;
         case 'edit':
             $old_values = Utils_RecordBrowserCommon::get_record('task', $values['id']);
             $old_related = array_merge($old_values['employees'], $old_values['customers']);
         case 'added':
             if (isset($values['follow_up'])) {
                 CRM_FollowupCommon::add_tracing_notes($values['follow_up'][0], $values['follow_up'][1], $values['follow_up'][2], 'task', $values['id'], $values['title']);
             }
             self::subscribed_employees($values);
             $related = array_merge($values['employees'], $values['customers']);
             foreach ($related as $v) {
                 if ($mode === 'edit' && in_array($v, $old_related)) {
                     continue;
                 }
                 if (!is_numeric($v)) {
                     list($t, $id) = explode(':', $v);
                 } else {
                     $t = 'P';
                     $id = $v;
                 }
                 if ($t == 'P') {
                     $t = 'contact';
                 } else {
                     $t = 'company';
                 }
                 $subs = Utils_WatchdogCommon::get_subscribers($t, $id);
                 foreach ($subs as $s) {
                     Utils_WatchdogCommon::user_subscribe($s, 'task', $values['id']);
                 }
             }
             break;
     }
     return $values;
 }
Exemplo n.º 2
0
    public static function submit_attachment($values, $mode) {
        static $new_values, $old_password;
        switch ($mode) {
            case 'browse':
                if (isset($values['id']) && isset($values['crypted']) && $values['crypted'] == false) {
                    // store to mark as read. Do not mark it here, because
                    // we won't get red eye in the table view
                    self::$mark_as_read[] = $values['id'];
                }
                return $values;
            case 'index':
                if($values['crypted']) unset($values['note']);
                return $values;
            case 'adding':
                $values['edited_on'] = time();
                return $values;
            case 'add':
            case 'edit':
                if(isset($values['__date'])) $values['edited_on'] = $values['__date'];
                else $values['edited_on'] = time();

                $crypted = 0;
                $old_pass = ($mode=='edit' && isset($_SESSION['client']['cp'.$values['id']]))?$_SESSION['client']['cp'.$values['id']]:($mode=='add' && isset($values['clone_id']) && isset($_SESSION['client']['cp'.$values['clone_id']])?$_SESSION['client']['cp'.$values['clone_id']]:'');
                if((is_array($values['crypted']) && isset($values['crypted']['crypted']) && $values['crypted']['crypted']) || (!is_array($values['crypted']) && $values['crypted'])) {
                    if(is_array($values['crypted']) && isset($values['crypted']['note_password'])) {
                        if($values['crypted']['note_password']=='*@#old@#*')
                            $values['crypted']['note_password'] = $old_pass;
                    }
                    $crypted = 1;
                }

                if(is_array($values['crypted']) && isset($values['crypted']['note_password']) && $mode=='edit' && $old_pass!=$values['crypted']['note_password']) {
                    //reencrypt old revisions
                    $old_notes = DB::GetAssoc('SELECT hd.edit_id,hd.old_value FROM utils_attachment_edit_history h INNER JOIN utils_attachment_edit_history_data hd ON h.id=hd.edit_id WHERE h.utils_attachment_id=%d AND hd.field="note"', array($values['id']));
                    foreach($old_notes as $old_id=>$old_note) {
                        if($old_pass!=='') $old_note = Utils_AttachmentCommon::decrypt($old_note,$old_pass);
                        if($old_note===false) continue;
                        if($crypted && $values['crypted']['note_password']) $old_note = Utils_AttachmentCommon::encrypt($old_note,$values['crypted']['note_password']);
                        if($old_note===false) continue;
                        DB::Execute('UPDATE utils_attachment_edit_history_data SET old_value=%s WHERE edit_id=%d AND field="note"',array($old_note,$old_id));
                    }
                    //file reencryption
                    $old_files = DB::GetCol('SELECT uaf.id as id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d',array($values['id']));
                    foreach($old_files as $old_id) {
                        $filename = DATA_DIR.'/Utils_Attachment/'.$values['id'].'/'.$old_id;
                        $content = @file_get_contents($filename);
                        if($content===false) continue;
                        if($old_pass!=='') $content = Utils_AttachmentCommon::decrypt($content,$old_pass);
                        if($content===false) continue;
                        if($crypted && $values['crypted']['note_password']) $content = Utils_AttachmentCommon::encrypt($content,$values['crypted']['note_password']);
                        if($content===false) continue;
                        file_put_contents($filename,$content);
                    }
                }

                if($crypted) {
                    if(is_array($values['crypted']) && isset($values['crypted']['note_password'])) {
                        $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$values['crypted']['note_password']);
                        $values['note_password']=$values['crypted']['note_password'];
                    }
                    $values['crypted'] = 1;
                } else {
                    $values['crypted'] = 0;
                }
                $new_values = $values;

                break;
            case 'cloning':
                $values['clone_id']=$values['id'];
                break;
            case 'added':
                if(isset($values['local']))
                    DB::Execute('INSERT INTO utils_attachment_local(attachment,local,func,args) VALUES(%d,%s,%s,%s)',array($values['id'],$values['local'],$values['func'],$values['args']));
                $new_values = $values;
                break;
            case 'edit_changes':
                if(isset($values['note']) && isset($values['crypted']) && $new_values['crypted']!=$values['crypted']) {
                    if($new_values['crypted'] && isset($new_values['note_password'])) {
                        $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$new_values['note_password']);
                    } elseif(!$new_values['crypted'] && isset($_SESSION['client']['cp'.$new_values['id']])) {
                        $values['note'] = Utils_AttachmentCommon::decrypt($values['note'],$_SESSION['client']['cp'.$new_values['id']]);
                        unset($_SESSION['client']['cp'.$new_values['id']]);
                    }
                } elseif(isset($new_values['note_password']) && isset($old_password) && $new_values['note_password']!=$old_password) {
                    $values['note'] = Utils_AttachmentCommon::decrypt($values['note'],$old_password);
                    $values['note'] = Utils_AttachmentCommon::encrypt($values['note'],$new_values['note_password']);
                }
                break;
            case 'view':
                $ret = self::get_access($values['id']);
                if(!$ret) print(__('Access denied'));
                return $ret;
            case 'display':
                if(DB::GetOne('SELECT 1 FROM utils_attachment_file WHERE attach_id=%d',array($values['id']))) {
                    $ret = array();
                    $ret['new'] = array();
                    $ret['new']['crm_filter'] = '<a '.Utils_TooltipCommon::open_tag_attrs(__('File history')).' '.Module::create_href(array('file_history'=>1)).'>F</a>';
                    if (isset($_REQUEST['file_history']) && (!$values['crypted'] || isset($_SESSION['client']['cp'.$values['id']])))
                        Base_BoxCommon::push_module('Utils_Attachment','file_history',array($values));
                    //    CRM_FiltersCommon::set_profile('c'.$values['id']);
                    return $ret;
                }
                break;
            case 'delete':
                if($values['crypted'] && !isset($_SESSION['client']['cp'.$values['id']])) {
                    Epesi::alert(__('Cannot delete encrypted note'));
                    return false;
                }
                $count_locals = DB::GetOne('SELECT count(DISTINCT local) FROM utils_attachment_local WHERE attachment=%d',array($values['id']));
                if($count_locals>1) {
                    $is_local = false;
                    if(isset($_SESSION['client']['utils_attachment_group']))
                        $is_local = DB::GetOne('SELECT 1 FROM utils_attachment_local WHERE attachment=%d AND local=%s',array($values['id'],$_SESSION['client']['utils_attachment_group']));
                    if($is_local) {
                        DB::Execute('DELETE FROM utils_attachment_local WHERE attachment=%d AND local=%s',array($values['id'],$_SESSION['client']['utils_attachment_group']));
                        self::new_watchdog_event($_SESSION['client']['utils_attachment_group'], '-', $values['id']);
                    } else
                        Epesi::alert(__('This note is attached to multiple records - please go to record and delete note there.'));
                    location(array());
                    return false;
                } 
                location(array());
                return true;
        }
        switch($mode) {
            case 'edit':
            case 'added':
                if(isset($values['note_password'])) {
                    $old_password = isset($_SESSION['client']['cp' . $values['id']])
                        ? $_SESSION['client']['cp' . $values['id']] : '';
                    $_SESSION['client']['cp'.$values['id']] = $values['note_password'];
                }

                $note_id = $values['id'];
                $files_dir = self::Instance()->get_data_dir().$note_id;
                
                if(isset($values['delete_files']))
                    $deleted_files = array_filter(explode(';',$values['delete_files']));
                else
                    $deleted_files = array();
                foreach ($deleted_files as $k=>$v)
                    $deleted_files[$k] = intVal($v);
                if($deleted_files) $deleted_files = array_combine($deleted_files,$deleted_files);
                
                if($mode=='added' && isset($values['clone_id'])) { //on cloning
                    $locals = DB::Execute('SELECT local,func,args FROM utils_attachment_local WHERE attachment=%d',array($values['clone_id']));
                    while($local = $locals->FetchRow())
                        DB::Execute('INSERT INTO utils_attachment_local(attachment,local,func,args) VALUES(%d,%s,%s,%s)',array($note_id,$local['local'],$local['func'],$local['args']));
                    
                    $clone_files = DB::GetAll('SELECT id,original,created_by,created_on FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($values['clone_id']));
                    foreach($clone_files as $file) {
                        $cf = self::Instance()->get_data_dir().$values['clone_id'].'/'.$file['id'];
                        if(!file_exists($cf)) continue;
                        if(!file_exists($files_dir))
                            mkdir($files_dir,0777,true);

                        DB::Execute('INSERT INTO utils_attachment_file (attach_id,deleted,original,created_by,created_on) VALUES(%d,0,%s,%d,%T)',array($note_id,$file['original'],$file['created_by'],$file['created_on']));
                        $new_file_id = DB::Insert_ID('utils_attachment_file','id');
                        if(isset($deleted_files[$file['id']])) $deleted_files[$file['id']] = $new_file_id;

                        $cf2 = $files_dir.'/'.$new_file_id;
                        copy($cf,$cf2);
                        if(isset($_SESSION['client']['cp'.$values['clone_id']]) && $_SESSION['client']['cp'.$values['clone_id']])
                            file_put_contents($cf2,Utils_AttachmentCommon::decrypt(file_get_contents($cf2),$_SESSION['client']['cp'.$values['clone_id']]));
                        if($values['crypted'])
                            file_put_contents($cf2,Utils_AttachmentCommon::encrypt(file_get_contents($cf2),$values['note_password']));
                    }
                }

                $current_files = DB::GetAssoc('SELECT id, id FROM utils_attachment_file uaf WHERE uaf.attach_id=%d AND uaf.deleted=0', array($note_id));
                $remaining_files = $current_files;
                foreach ($deleted_files as $k=>$v) {
                    if (!isset($remaining_files[$v])) unset($deleted_files[$k]);
                    else unset($remaining_files[$v]);
                }
                foreach ($deleted_files as $v)
                    DB::Execute('UPDATE utils_attachment_file SET deleted=1 WHERE id=%d', array($v));

                if(isset($values['clipboard_files'])) {
                    $clipboard_files = array_filter(explode(';',$values['clipboard_files']));
                    foreach ($clipboard_files as $cf_id) {
                        $cf = DB::GetOne('SELECT filename FROM utils_attachment_clipboard WHERE id=%d', array($cf_id));
                        if($values['crypted'])
                            file_put_contents($cf,Utils_AttachmentCommon::encrypt(file_get_contents($cf),$values['note_password']));
                        Utils_AttachmentCommon::add_file($note_id, Acl::get_user(), __('clipboard').'.png', $cf);
                    }
                }

                $files = isset($_SESSION['client']['utils_attachment'][CID]['files'])?$_SESSION['client']['utils_attachment'][CID]['files']:array();
                $_SESSION['client']['utils_attachment'][CID]['files'] = array();
                foreach ($files as $f) {
                    $file_path = $f['path'];
                    $file_name = $f['name'];
                    if($values['crypted'])
                        file_put_contents($file_path,Utils_AttachmentCommon::encrypt(file_get_contents($file_path),$values['note_password']));
                    Utils_AttachmentCommon::add_file($note_id, Acl::get_user(), $file_name, $file_path);
                }

                $locals = DB::GetCol('SELECT local FROM utils_attachment_local WHERE attachment=%d',array($note_id));
                foreach ($locals as $local) {
                    $param = explode('/', $local);
                    if (count($param) == 2 && preg_match('/^[1-9][0-9]*$/', $param[1])) {
                        $subscribers = Utils_WatchdogCommon::get_subscribers($param[0], $param[1]);
                        foreach ($subscribers as $user_id) {
                            Utils_WatchdogCommon::user_subscribe($user_id, 'utils_attachment', $note_id);
                        }
                    }
                }

                break;
        }
        return $values;
    }
Exemplo n.º 3
0
 public static function submit_meeting($values, $mode)
 {
     $me = CRM_ContactsCommon::get_my_record();
     switch ($mode) {
         case 'delete':
             Utils_MessengerCommon::delete_by_id('CRM_Calendar_Event:' . $values['id']);
             break;
         case 'display':
             $pdf = Utils_RecordBrowser::$rb_obj->pack_module('Libs/TCPDF', 'L');
             if ($pdf->prepare()) {
                 $pdf->set_title($values['title']);
                 $pdf->set_subject('');
                 $pdf->prepare_header();
                 $pdf->AddPage();
                 $v = CRM_Calendar_EventCommon::get(DB::GetOne('SELECT id FROM crm_calendar_custom_events_handlers WHERE group_name=%s', array('Meetings')) . '#' . $values['id']);
                 $ev_mod = Utils_RecordBrowser::$rb_obj->init_module('CRM/Calendar/Event');
                 $ev_mod->make_event_PDF($pdf, $v, true, 'view');
             }
             $pdf->add_actionbar_icon('Print');
             if (isset($_REQUEST['day'])) {
                 $values['date'] = $_REQUEST['day'];
             }
             $ret = array();
             if ($values['time']) {
                 // normal event
                 $start = $values['time'];
                 // time in unix timestamp UTC
                 $start_disp = strtotime(Base_RegionalSettingsCommon::time2reg($start, true, true, true, false));
             } else {
                 // when event is timeless - all day event
                 $time = $values['date'] . ' 00:00:01';
                 $start = Base_RegionalSettingsCommon::reg2time($time);
                 $start_disp = strtotime($time);
             }
             $end = strtotime('+' . $values['duration'] . ' seconds', $start);
             $ret['day_details'] = array('start' => array('day' => '<a ' . Base_BoxCommon::create_href(null, 'CRM/Calendar', 'body', array(array('default_view' => 'day', 'default_date' => strtotime($values['date']))), array()) . '>' . date('j', $start_disp) . '</a>', 'month' => '<a ' . Base_BoxCommon::create_href(null, 'CRM/Calendar', 'body', array(array('default_view' => 'month', 'default_date' => strtotime($values['date']))), array()) . '>' . __date('F', $start_disp) . '</a>', 'year' => '<a ' . Base_BoxCommon::create_href(null, 'CRM/Calendar', 'body', array(array('default_view' => 'year', 'default_date' => strtotime($values['date']))), array()) . '>' . date('Y', $start_disp) . '</a>', 'weekday' => '<a ' . Base_BoxCommon::create_href(null, 'CRM/Calendar', 'body', array(array('default_view' => 'week', 'default_date' => strtotime($values['date']))), array()) . '>' . __date('l', $start_disp) . '</a>'));
             if (!isset($values['timeless']) || !$values['timeless']) {
                 $ret['event_info'] = array('start_time' => Base_RegionalSettingsCommon::time2reg($start, 2, false), 'end_time' => Base_RegionalSettingsCommon::time2reg($end, 2, false), 'duration' => Base_RegionalSettingsCommon::seconds_to_words($values['duration']), 'start_date' => '-', 'end_date' => '-');
             }
             $ret['form_data']['timeless'] = array('label' => __('Timeless'), 'html' => 'value');
             $ret['toggle_duration'] = 'tog';
             $ret['duration_block_id'] = '1';
             $ret['event_end_block_id'] = '2';
             $values['title'] = __('Follow-up') . ': ' . $values['title'];
             $values['status'] = 0;
             $cus = reset($values['customers']);
             if (ModuleManager::is_installed('CRM/Meeting') >= 0) {
                 $ret['new']['event'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Meeting')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('crm_meeting', array('title' => $values['title'], 'permission' => $values['permission'], 'priority' => $values['priority'], 'description' => $values['description'], 'date' => date('Y-m-d'), 'time' => date('H:i:s'), 'duration' => 3600, 'employees' => $values['employees'], 'customers' => $values['customers'], 'status' => 0), 'none', false) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Calendar', 'icon-small.png') . '" /></a>';
             }
             if (ModuleManager::is_installed('CRM/Tasks') >= 0) {
                 $ret['new']['task'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Task')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('task', array('title' => $values['title'], 'permission' => $values['permission'], 'priority' => $values['priority'], 'description' => $values['description'], 'employees' => $values['employees'], 'customers' => $values['customers'], 'status' => 0, 'deadline' => date('Y-m-d', strtotime('+1 day')))) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_Tasks', 'icon-small.png') . '"></a>';
             }
             if (ModuleManager::is_installed('CRM/PhoneCall') >= 0) {
                 $ret['new']['phonecall'] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('New Phonecall')) . ' ' . Utils_RecordBrowserCommon::create_new_record_href('phonecall', array('subject' => $values['title'], 'permission' => $values['permission'], 'priority' => $values['priority'], 'description' => $values['description'], 'date_and_time' => date('Y-m-d H:i:s'), 'employees' => $values['employees'], 'customer' => $cus, 'status' => 0), 'none', false) . '><img border="0" src="' . Base_ThemeCommon::get_template_file('CRM_PhoneCall', 'icon-small.png') . '" /></a>';
             }
             $ret['new']['note'] = Utils_RecordBrowser::$rb_obj->add_note_button('crm_meeting/' . $values['id']);
             return $ret;
         case 'edit':
             self::subscribed_employees($values);
             $alarms = Utils_MessengerCommon::get_alarms('CRM_Calendar_Event:' . $values['id']);
             $old = Utils_RecordBrowserCommon::get_record('crm_meeting', $values['id']);
             $old_time = strtotime($old['date'] . ' ' . date('H:i:s', strtotime($old['time'])));
             $new_time = strtotime($values['date'] . ' ' . date('H:i:s', strtotime($values['time'])));
             foreach ($alarms as $id => $time) {
                 $time = strtotime($time);
                 $diff = $old_time - $time;
                 Utils_MessengerCommon::update_time($id, $new_time - $diff);
             }
         case 'add':
             if (isset($values['duration_switch']) && !$values['duration_switch']) {
                 $values['duration'] = strtotime($values['end_time']) - strtotime($values['time']);
                 if ($values['duration'] < 0) {
                     $values['duration'] += 60 * 60 * 24;
                 }
                 // failsafe
             }
             if (isset($values['timeless']) && $values['timeless']) {
                 $values['duration'] = -1;
             }
             $new = '';
             foreach (array(0 => 'Mon', 1 => 'Tue', 2 => 'Wed', 3 => 'Thu', 4 => 'Fri', 5 => 'Sat', 6 => 'Sun') as $k => $v) {
                 if (isset($values['recurrence_hash_' . $k]) && $values['recurrence_hash_' . $k]) {
                     $new .= '1';
                 } else {
                     $new .= '0';
                 }
             }
             if ($new != '0000000') {
                 $values['recurrence_hash'] = $new;
             }
             if ($values['duration'] != -1) {
                 if (isset($values['modded'])) {
                     $time = Base_RegionalSettingsCommon::time2reg($values['time'], true, true, true, false);
                     $reg_timestamp = $values['date'] . ' ' . date('H:i:s', strtotime($time));
                     $timestamp = Base_RegionalSettingsCommon::reg2time($reg_timestamp);
                     $values['date'] = date('Y-m-d', $timestamp);
                     $values['time'] = date('Y-m-d H:i:s', $timestamp);
                     if (isset($values['recurrence_end']) && $values['recurrence_end']) {
                         $values['recurrence_end'] = date('Y-m-d', Base_RegionalSettingsCommon::reg2time($values['recurrence_end'] . ' ' . date('H:i:s', strtotime($time))));
                         if ($values['recurrence_end'] < $values['date']) {
                             $values['recurrence_end'] = $values['date'];
                         }
                         if ($values['recurrence_type'] == 8) {
                             $date = date('Y-m-d', strtotime('+6 days', strtotime($values['date'])));
                             if ($values['recurrence_end'] < $date) {
                                 $values['recurrence_end'] = $date;
                             }
                         }
                     }
                 }
             } else {
                 $values['time'] = '';
             }
             break;
         case 'adding':
             $values['permission'] = Base_User_SettingsCommon::get('CRM_Common', 'default_record_permission');
         case 'editing':
         case 'view':
             $values['modded'] = 1;
             if (!isset($values['date'])) {
                 $values['date'] = date('Y-m-d');
             }
             if (!isset($values['time'])) {
                 $values['time'] = time();
             }
             if (!isset($values['duration'])) {
                 $values['duration'] = 3600;
             }
             if (!is_numeric($values['time'])) {
                 $values['time'] = strtotime($values['time']);
             }
             if ($values['duration'] != -1) {
                 if (isset($values['date']) && $values['date']) {
                     $values['date'] = Base_RegionalSettingsCommon::time2reg($values['date'] . ' ' . date('H:i:s', $values['time']), false, true, true, false);
                     $values['time'] = Base_RegionalSettingsCommon::time2reg($values['date'] . ' ' . date('H:i:s', $values['time']), true, false, true, false);
                     $values['time'] = Base_RegionalSettingsCommon::reg2time($values['date'] . ' ' . $values['time']);
                 }
                 if (isset($values['recurrence_end']) && $values['recurrence_end']) {
                     $values['recurrence_end'] = Base_RegionalSettingsCommon::time2reg($values['recurrence_end'] . ' ' . date('H:i:s', $values['time']), false, true, true, false);
                 }
             }
             break;
         case 'added':
             if (isset($values['follow_up'])) {
                 CRM_FollowupCommon::add_tracing_notes($values['follow_up'][0], $values['follow_up'][1], $values['follow_up'][2], 'meeting', $values['id'], $values['title']);
             }
             self::subscribed_employees($values);
             $related = array_merge($values['employees'], $values['customers']);
             foreach ($related as $v) {
                 if ($mode === 'edit' && in_array($v, $old_related)) {
                     continue;
                 }
                 if (!is_numeric($v)) {
                     list($t, $id) = explode(':', $v);
                 } else {
                     $t = 'P';
                     $id = $v;
                 }
                 if ($t == 'P') {
                     $t = 'contact';
                 } else {
                     $t = 'company';
                 }
                 $subs = Utils_WatchdogCommon::get_subscribers($t, $id);
                 foreach ($subs as $s) {
                     Utils_WatchdogCommon::user_subscribe($s, 'crm_meeting', $values['id']);
                 }
             }
             if (isset($values['messenger_on']) && $values['messenger_on'] != 'none') {
                 $start = strtotime($values['date'] . ' ' . date('H:i:s', strtotime($values['time'])));
                 if ($values['messenger_on'] == 'me') {
                     Utils_MessengerCommon::add('CRM_Calendar_Event:' . $values['id'], 'CRM_Meeting', $values['messenger_message'], $start - $values['messenger_before'], array('CRM_MeetingCommon', 'get_alarm'), array($values['id']));
                 } else {
                     $eee = array();
                     foreach ($values['employees'] as $v) {
                         $c = CRM_ContactsCommon::get_contact($v);
                         if (isset($c['login'])) {
                             $eee[] = $c['login'];
                         }
                     }
                     Utils_MessengerCommon::add('CRM_Calendar_Event:' . $values['id'], 'CRM_Meeting', $values['messenger_message'], $start - $values['messenger_before'], array('CRM_MeetingCommon', 'get_alarm'), array($values['id']), $eee);
                 }
             }
             break;
     }
     return $values;
 }
Exemplo n.º 4
0
 public static function subscribe_users_to_record($record)
 {
     $employee = $record['employee'];
     $contacts = $record['contacts'];
     $subscribers = $employee ? Utils_WatchdogCommon::get_subscribers('contact', $employee) : array();
     foreach ($contacts as $c) {
         list($rs, $con_id) = explode(':', $c);
         $rs_full = $rs == 'P' ? 'contact' : 'company';
         $subscribers = array_merge($subscribers, Utils_WatchdogCommon::get_subscribers($rs_full, $con_id));
     }
     foreach (array_unique($subscribers) as $user_id) {
         Utils_WatchdogCommon::user_subscribe($user_id, 'rc_mails', $record['id']);
     }
 }