public static function prepare_header(&$tcpdf, $title = '', $subject = '', $printed_by = true, $logo_filename = null, $l = array()) { if ($title !== null) { if ($logo_filename === null) { $logo_filename = Libs_TCPDFCommon::get_logo_filename(); } if ($logo_filename !== false && !file_exists($logo_filename)) { $logo_filename = Base_ThemeCommon::get_template_file(Libs_TCPDF::module_name(), 'logo-small.png'); } $margins = $tcpdf->getMargins(); if ($logo_filename) { $logo_size = getimagesize($logo_filename); $logo_height = $logo_size[1] * PDF_HEADER_LOGO_WIDTH / $logo_size[0]; } else { $logo_height = 0; } $tcpdf->SetHeaderMargin(10); $tcpdf->SetTopMargin($logo_height + $margins['top']); $tcpdf->SetHeaderData($logo_filename, $logo_filename ? PDF_HEADER_LOGO_WIDTH : 0, $title, $subject); } else { $tcpdf->setPrintHeader(false); } //set some language-dependent strings $l['a_meta_charset'] = "UTF-8"; $l['a_meta_dir'] = "ltr"; $l['a_meta_language'] = "pl"; $who = null; if (CRM_ContactsInstall::is_installed()) { $who = CRM_ContactsCommon::get_contact_by_user_id(Acl::get_user()); } if ($who !== null) { $who = $who['last_name'] . ' ' . $who['first_name']; } else { $who = Base_UserCommon::get_user_login(Acl::get_user()); } $when = date('Y-m-d H:i:s'); if (!isset($l['w_page'])) { $l['w_page'] = ''; if ($printed_by) { $product_name = EPESI; $url = EPESI == 'EPESI' ? ' (http://epe.si)' : ''; $l['w_page'] .= __('Printed with %s by %s, on %s, ', array($product_name . $url, $who, $when)); } $l['w_page'] .= __('Page'); } $tcpdf->setLanguageArray($l); self::SetFont($tcpdf, self::$default_font, '', 9); }
public function body($pdf = false, $charts = false) { if ($this->is_back()) { return false; } if ($this->date_range == 'error') { return; } Base_ThemeCommon::load_css('Utils/RecordBrowser/Reports'); $this->pdf = $pdf || isset($_REQUEST['rb_reports_enable_pdf']); $this->csv = isset($_REQUEST['rb_reports_enable_csv']); unset($_REQUEST['rb_reports_enable_pdf']); $this->charts = $charts; if ($this->pdf) { $this->pdf_ob = $this->init_module(Libs_TCPDF::module_name(), 'L'); $this->pdf_ob->set_title($this->pdf_title); $this->pdf_ob->set_subject($this->pdf_subject); $this->pdf_ob->prepare_header(); $this->pdf_ob->AddPage(); } elseif (!$this->charts && !$this->csv) { Base_ActionBarCommon::add('report', __('Charts'), $this->create_callback_href(array($this, 'body'), array(false, true))); } if ($this->charts) { $this->make_charts(); } else { $this->make_table(); } if ($this->csv) { $this->set_module_variable('csv', $this->csv_ob); } if ($charts) { Base_ActionBarCommon::add('report', __('Table'), $this->create_back_href()); return true; } else { if (!$this->csv) { if ($this->pdf) { Base_ActionBarCommon::add('save', __('Download PDF'), 'target="_blank" href="' . $this->pdf_ob->get_href($this->pdf_filename) . '"'); self::$pdf_ready = 1; } elseif ($this->pdf_title != '' && self::$pdf_ready == 0) { if (count($this->gb_captions) < 20) { Base_ActionBarCommon::add('print', __('Create PDF'), $this->create_href(array('rb_reports_enable_pdf' => 1))); } else { Base_ActionBarCommon::add('print', __('Create PDF'), '', __('Too many columns to prepare printable version - please limit number of columns')); } } } if ($this->pdf_filename && !$this->pdf) { if ($this->csv) { Base_ActionBarCommon::add('save', __('Download CSV'), 'target="_blank" href="' . $this->get_module_dir() . '/csv.php?' . http_build_query(array('p' => $this->get_path(), 'id' => CID, 'filename' => $this->pdf_filename)) . '"'); } else { Base_ActionBarCommon::add('print', __('Create CSV'), $this->create_href(array('rb_reports_enable_csv' => 1))); } } } return false; }
public function body($args = array()) { $ev_mod = $this->init_module(CRM_Calendar_Event::module_name()); $ev_mod->help('Calendar Help', 'main'); if (isset($_REQUEST['search_date']) && is_numeric($_REQUEST['search_date']) && isset($_REQUEST['ev_id']) && is_numeric($_REQUEST['ev_id'])) { $default_date = intval($_REQUEST['search_date']); $this->view_event(intval($_REQUEST['ev_id'])); } else { $default_date = null; } $handlers = DB::GetAll('SELECT id, group_name, handler_callback FROM crm_calendar_custom_events_handlers'); $this->lp = $this->init_module('Utils_LeightboxPrompt'); $count = 0; foreach ($handlers as $v) { $callback = explode('::', $v['handler_callback']); if (!is_callable($callback)) { continue; } $new_events = call_user_func($callback, 'new_event_types'); if ($new_events !== null) { foreach ($new_events as $k => $w) { if (!is_array($w)) { $w = array('label' => $w, 'icon' => null); } $this->lp->add_option('new_event__' . $v['id'] . '__' . $k, $w['label'], $w['icon'], null); $count++; } } } if ($count < 2) { $this->lp = null; } else { $this->display_module($this->lp, array(__('New Event'), array('timestamp', 'timeless'), '', false)); $vals = $this->lp->export_values(); if ($vals) { $this->jump_to_new_event($vals['option'], $vals['params']['timestamp'], $vals['params']['timeless']); return; } } CRM_Calendar_EventCommon::$filter = CRM_FiltersCommon::get(); $args_defaults = array('default_view' => Base_User_SettingsCommon::get('CRM_Calendar', 'default_view'), 'first_day_of_week' => Utils_PopupCalendarCommon::get_first_day_of_week(), 'start_day' => Base_User_SettingsCommon::get('CRM_Calendar', 'start_day'), 'end_day' => Base_User_SettingsCommon::get('CRM_Calendar', 'end_day'), 'interval' => Base_User_SettingsCommon::get('CRM_Calendar', 'interval'), 'default_date' => $default_date, 'custom_agenda_cols' => array(array('name' => __('Type'), 'order' => 'cus_col_0', 'width' => 6, 'wrapmode' => 'nowrap'), __('Description'), __('Assigned to'), __('Related with'))); foreach ($args_defaults as $k => $v) { if (!isset($args[$k])) { $args[$k] = $args_defaults[$k]; } } if (isset($_REQUEST['jump_to_date']) && is_numeric($_REQUEST['jump_to_date']) && isset($_REQUEST['switch_to_tab']) && is_string($_REQUEST['switch_to_tab'])) { $args['default_date'] = $_REQUEST['jump_to_date']; $args['default_view'] = $_REQUEST['switch_to_tab']; } $theme = $this->init_module(Base_Theme::module_name()); $c = $this->init_module(Utils_Calendar::module_name(), array(CRM_Calendar_Event::module_name(), $args, array($this, 'get_new_event_href_js'))); $view_type = $c->get_current_view(); CRM_CalendarCommon::$mode = $view_type; $theme->assign('calendar', $this->get_html_of_module($c)); $theme->display(); $events = $c->get_displayed_events(); if (!empty($events['events'])) { switch ($view_type) { case 'Day': $view = __('Daily agenda'); break; case 'Month': $view = __('Monthly agenda'); break; case 'Week': $view = __('Weekly agenda'); break; case 'Agenda': $view = __('Agenda'); break; } if (isset($view)) { $pdf = $this->pack_module(Libs_TCPDF::module_name(), null, null, 'L'); if ($pdf->prepare()) { set_time_limit(0); $start = date('d F Y', Base_RegionalSettingsCommon::reg2time($events['start'])); $end = date('d F Y', Base_RegionalSettingsCommon::reg2time($events['end'])); $pdf->set_title($view . ', ' . $start . ($view_type != 'Day' ? ' - ' . $end : '')); $filter = CRM_FiltersCommon::get(); $me = CRM_ContactsCommon::get_my_record(); if (trim($filter, '()') == $me['id']) { $desc = $me['last_name'] . ' ' . $me['first_name']; } else { $desc = CRM_FiltersCommon::get_profile_desc(); } $pdf->set_subject(__('CRM Filters: %s', array($desc))); $pdf->prepare_header(); $pdf->AddPage(); foreach ($events['events'] as $v) { $ev_mod->make_event_PDF($pdf, $v, true, $view_type); } } $pdf->add_actionbar_icon($view); } } }
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::module_name(), '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::module_name()); $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::module_name(), '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::module_name(), '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::module_name(), '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::module_name(), '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 (CRM_MeetingInstall::is_installed()) { $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 (CRM_TasksInstall::is_installed()) { $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 (CRM_PhoneCallInstall::is_installed()) { $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; }