public static function cut_string($str, $len, $tooltip = true, &$cut = null)
 {
     return $str;
     if ($len == -1) {
         return $str;
     }
     $ret = '';
     $strings = explode('<br>', $str);
     foreach ($strings as $str) {
         if ($ret) {
             $ret .= '<br>';
         }
         $label = '';
         $i = 0;
         $curr_len = 0;
         $tags = array();
         $inside = 0;
         preg_match_all('/./u', $str, $a);
         $a = $a[0];
         $strlen = count($a);
         while ($curr_len <= $len && $i < $strlen) {
             if ($a[$i] == '&' && !$inside) {
                 $e = -1;
                 if (isset($a[$i + 3]) && $a[$i + 3] == ';') {
                     $e = 3;
                 } elseif (isset($a[$i + 4]) && $a[$i + 4] == ';') {
                     $e = 4;
                 } elseif (isset($a[$i + 5]) && $a[$i + 5] == ';') {
                     $e = 5;
                 }
                 if ($e != -1) {
                     $hsc = implode("", array_slice($a, $i, $e + 1));
                     if ($hsc == '&nbsp;' || strlen(htmlspecialchars_decode($hsc)) == 1) {
                         $label .= implode("", array_slice($a, $i, $e));
                         $i += $e;
                         $curr_len++;
                     }
                 }
             } elseif ($a[$i] == '<' && !$inside) {
                 $inside = 1;
                 if (isset($a[$i + 1]) && $a[$i + 1] == '/') {
                     if (!empty($tags)) {
                         array_pop($tags);
                     }
                 } else {
                     $j = 1;
                     $next_tag = '';
                     while ($i + $j <= $strlen && $a[$i + $j] != ' ' && $a[$i + $j] != '>' && $a[$i + $j] != '/') {
                         $next_tag .= $a[$i + $j];
                         $j++;
                     }
                     $tags[] = $next_tag;
                 }
             } elseif ($a[$i] == '"' && $inside == 1) {
                 $inside = 2;
             } elseif ($a[$i] == '"' && $inside == 2) {
                 $inside = 1;
             } elseif ($a[$i] == '>' && $inside == 1) {
                 if ($i > 0 && $a[$i - 1] == '/') {
                     array_pop($tags);
                 }
                 $inside = 0;
             } elseif (!$inside) {
                 $curr_len++;
             }
             $label .= $a[$i];
             $i++;
         }
         if ($i < $strlen) {
             $cut = true;
             $label .= '...';
             if ($tooltip) {
                 if (!strpos($str, 'Utils_Toltip__showTip(')) {
                     $label = '<span ' . Utils_TooltipCommon::open_tag_attrs(strip_tags($str)) . '>' . $label . '</span>';
                 } else {
                     $label = preg_replace('/Utils_Toltip__showTip\\(\'(.*?)\'/', 'Utils_Toltip__showTip(\'' . escapeJS(htmlspecialchars($str)) . '<hr>$1\'', $label);
                 }
             }
         }
         while (!empty($tags)) {
             $label .= '</' . array_pop($tags) . '>';
         }
         $ret .= $label;
     }
     return $ret;
 }
Exemple #2
0
 private function get_link($i, $val, $caption, $parent = null)
 {
     if ($parent === null) {
         $parent = '';
     } else {
         $parent = ' parent_menu="' . $parent . '"';
     }
     $path = escapeJS($this->get_path());
     if ($this->page === $i || is_string($this->page) && $this->page == $caption) {
         $selected = ' class="tabbed_browser_selected"';
     } else {
         $selected = ' class="tabbed_browser_unselected"';
     }
     $icon = '<img class="tab_icon" id="' . $this->get_tab_id($caption) . '_icon" src="" style="display:none;">';
     if (isset($val['href']) && $val['href']) {
         $link = '<span id="' . $this->get_tab_id($caption) . '"' . $parent . ' ' . $val['href'] . '>' . $caption . $icon . '</span>';
     } elseif ($val['js']) {
         $link = '<span id="' . $this->get_tab_id($caption) . '"' . $parent . ' href="javascript:void(0)" onClick="tabbed_browser_switch(' . $i . ',' . $this->max . ',this,\'' . $path . '\')"' . $selected . '>' . $caption . $icon . '</span>';
     } else {
         $link = '<span id="' . $this->get_tab_id($caption) . '"' . $parent . ' href="javascript:void(0)" onClick="tabbed_browser_switch(' . $i . ',' . $this->max . ',this,\'' . $path . '\')"' . $selected . ' original_action="' . $this->create_unique_href_js(array('page' => $i)) . '">' . $caption . $icon . '</span>';
     }
     return $link;
 }
Exemple #3
0
    public function view_edit_history($id){
		load_js('modules/Utils/RecordBrowser/edit_history.js');
        if ($this->is_back())
            return $this->back();
        $this->init();
		$tb = $this->init_module('Utils_TabbedBrowser');		
        $gb_cha = $this->init_module('Utils/GenericBrowser', null, $this->tab.'__changes');
		$form = $this->init_module('Libs_QuickForm');

        $table_columns_changes = array( array('name'=>__('Date'), 'width'=>10, 'wrapmode'=>'nowrap'),
                                        array('name'=>__('Username'), 'width'=>10, 'wrapmode'=>'nowrap'),
                                        array('name'=>__('Field'), 'width'=>10, 'wrapmode'=>'nowrap'),
                                        array('name'=>__('Old value'), 'width'=>10, 'wrapmode'=>'nowrap'),
                                        array('name'=>__('New value'), 'width'=>10, 'wrapmode'=>'nowrap'));

        $gb_cha->set_table_columns( $table_columns_changes );

        $gb_cha->set_inline_display();

        $created = Utils_RecordBrowserCommon::get_record($this->tab, $id, true);
        $access = $this->get_access('view', $created);
        $field_hash = array();
        $edited = DB::GetRow('SELECT ul.login, c.edited_on FROM '.$this->tab.'_edit_history AS c LEFT JOIN user_login AS ul ON ul.id=c.edited_by WHERE c.'.$this->tab.'_id=%d ORDER BY edited_on DESC',array($id));
        foreach($this->table_rows as $field => $args)
            $field_hash[$args['id']] = $field;

        $ret = DB::Execute('SELECT ul.login, c.id, c.edited_on, c.edited_by FROM '.$this->tab.'_edit_history AS c LEFT JOIN user_login AS ul ON ul.id=c.edited_by WHERE c.'.$this->tab.'_id=%d ORDER BY edited_on DESC, id DESC',array($id));
		$dates_select = array();
		$tb_path = escapeJS($tb->get_path());
        while ($row = $ret->FetchRow()) {
			$user = Base_UserCommon::get_user_label($row['edited_by']);
			$date_and_time = Base_RegionalSettingsCommon::time2reg($row['edited_on']);
            $changed = array();
            $ret2 = DB::Execute('SELECT * FROM '.$this->tab.'_edit_history_data WHERE edit_id=%d',array($row['id']));
            while($row2 = $ret2->FetchRow()) {
                if ($row2['field']!='id' && (!isset($access[$row2['field']]) || !$access[$row2['field']])) continue;
                $changed[$row2['field']] = $row2['old_value'];
                $last_row = $row2;
                $dates_select[$row['edited_on']] = $date_and_time;
            }
            foreach($changed as $k=>$v) {
                if ($k=='id') {
					$gb_cha->add_row(
						$date_and_time, 
						$user, 
						array('value'=>_V($last_row['old_value']), 'attrs'=>'colspan="3" style="text-align:center;font-weight:bold;"'),
						array('value'=>'', 'dummy'=>true),
						array('value'=>'', 'dummy'=>true)
					);
                } else {
                    if (!isset($field_hash[$k])) continue;
                    $new = $this->get_val($field_hash[$k], $created, false, $this->table_rows[$field_hash[$k]]);
                    if ($this->table_rows[$field_hash[$k]]['type']=='multiselect') $v = Utils_RecordBrowserCommon::decode_multi($v);
                    $created[$k] = $v;
                    $old = $this->get_val($field_hash[$k], $created, false, $this->table_rows[$field_hash[$k]]);
					$gb_row = $gb_cha->get_new_row();
					$gb_row->add_action('href="javascript:void(0);" onclick="recordbrowser_edit_history_jump(\''.$row['edited_on'].'\',\''.$this->tab.'\','.$created['id'].',\''.$form->get_name().'\');tabbed_browser_switch(1,2,null,\''.$tb_path.'\')"','View');
                    $gb_row->add_data(
                        $date_and_time,
                        $row['edited_by']!==null?$user:'',
                        _V($this->table_rows[$field_hash[$k]]['name']), // TRSL
                        $old,
                        $new
                    );
                }
            }
        }

		$gb_row = $gb_cha->get_new_row();
		$gb_row->add_data(
			Base_RegionalSettingsCommon::time2reg($created['created_on']),
			$created['created_by']!==null?Base_UserCommon::get_user_label($created['created_by']):'',
			array('value'=>__('RECORD CREATED'), 'attrs'=>'colspan="3" style="text-align:center;font-weight:bold;"'),
			array('value'=>'', 'dummy'=>true),
			array('value'=>'', 'dummy'=>true)
		);


//		$tb->set_tab(__('Record historical view'), array($this, 'record_historical_view'), array($created, $access, $form, $dates_select), true);
		$tb->start_tab(__('Changes History'));
		$this->display_module($gb_cha);
		$tb->end_tab();

		$tb->start_tab(__('Record historical view'));
		$dates_select[$created['created_on']] = Base_RegionalSettingsCommon::time2reg($created['created_on']);
        foreach($this->table_rows as $field => $args) {
            if (!$access[$args['id']]) continue;
            $val = $this->get_val($field, $created, false, $args);
        }
		$form->addElement('select', 'historical_view_pick_date', __('View the record as of'), $dates_select, array('onChange'=>'recordbrowser_edit_history("'.$this->tab.'",'.$created['id'].',"'.$form->get_name().'");', 'id'=>'historical_view_pick_date'));
		$form->setDefaults(array('historical_view_pick_date'=>$created['created_on']));
		$form->display();
		$this->view_entry('history', $created);
		$tb->end_tab();

		
		$this->display_module($tb);
        Base_ActionBarCommon::add('back',__('Back'),$this->create_back_href());
        return true;
    }
Exemple #4
0
 public static function QFfield_company(&$form, $field, $label, $mode, $default, $desc, $rb, $display_callbacks)
 {
     static $showed_create_company = false;
     if (($mode == 'add' || $mode == 'edit') && is_object($rb) && $rb->tab === 'contact' && !$showed_create_company) {
         $showed_create_company = true;
         if (self::$paste_or_new == 'new') {
             $access = Utils_RecordBrowserCommon::get_access('contact', $mode, Utils_RecordBrowser::$last_record);
             $c_access = Utils_RecordBrowserCommon::get_access('company', 'add');
             if ($c_access && $access['company_name']) {
                 $form->addElement('checkbox', 'create_company', __('Create new company'), null, 'onClick="document.getElementById(\'company_name\').disabled = this.checked;document.getElementsByName(\'create_company_name\')[0].disabled=!this.checked;" ' . Utils_TooltipCommon::open_tag_attrs(__('Create a new company for this contact')));
                 $form->addElement('text', 'create_company_name', __('New company name'), array('disabled' => 1));
                 $form->addFormRule(array('CRM_ContactsCommon', 'check_new_company_name'));
                 if (isset($rb) && isset($rb->record['last_name']) && isset($rb->record['first_name'])) {
                     $form->setDefaults(array('create_company_name' => $rb->record['last_name'] . ' ' . $rb->record['first_name']));
                 }
                 eval_js('Event.observe(\'last_name\',\'change\', update_create_company_name_field);' . 'Event.observe(\'first_name\',\'change\', update_create_company_name_field);' . 'function update_create_company_name_field() {' . 'document.forms[\'' . $form->getAttribute('name') . '\'].create_company_name.value = document.forms[\'' . $form->getAttribute('name') . '\'].last_name.value+" "+document.forms[\'' . $form->getAttribute('name') . '\'].first_name.value;' . '}');
                 eval_js('$("company_name").disabled = document.getElementsByName("create_company")[0].checked;document.getElementsByName("create_company_name")[0].disabled=!document.getElementsByName("create_company")[0].checked;');
             }
         } else {
             $comp = self::get_company(self::$paste_or_new);
             foreach ($comp as &$cf) {
                 if (is_string($cf)) {
                     $cf = escapeJS($cf);
                 }
             }
             $paste_company_info = 'document.getElementsByName(\'address_1\')[0].value=\'' . $comp['address_1'] . '\';' . 'document.getElementsByName(\'address_2\')[0].value=\'' . $comp['address_2'] . '\';' . 'document.getElementsByName(\'work_phone\')[0].value=\'' . $comp['phone'] . '\';' . 'document.getElementsByName(\'fax\')[0].value=\'' . $comp['fax'] . '\';' . 'document.getElementsByName(\'city\')[0].value=\'' . $comp['city'] . '\';' . 'document.getElementsByName(\'postal_code\')[0].value=\'' . $comp['postal_code'] . '\';' . 'var country = $(\'country\');' . 'var k = 0; while (k < country.options.length) if (country.options[k].value==\'' . $comp['country'] . '\') break; else k++;' . 'country.selectedIndex = k;' . 'country.fire(\'e_u_cd:load\');' . 'setTimeout(\'' . 'var zone = $(\\\'zone\\\'); k = 0; while (k < zone.options.length) if (zone.options[k].value==\\\'' . $comp['zone'] . '\\\') break; else k++;' . 'zone.selectedIndex = k;' . '\',900);' . 'document.getElementsByName(\'web_address\')[0].value=\'' . $comp['web_address'] . '\';';
             Base_ActionBarCommon::add('add', __('Paste Company Info'), 'href="javascript:void(0);" onclick="' . $paste_company_info . '"');
         }
     }
     $comp = array();
     $param = explode(';', $desc['param']);
     if ($mode == 'add' || $mode == 'edit') {
         if (isset($param[1]) && $param[1] != '::') {
             $crits = call_user_func(explode('::', $param[1]), false, isset($rb->record) ? $rb->record : null);
         } else {
             $crits = array();
         }
         if (isset($crits['_no_company_option'])) {
             $no_company_option = true;
             unset($crits['_no_company_option']);
         } else {
             $no_company_option = false;
         }
         $count = Utils_RecordBrowserCommon::get_records_count('company', $crits);
         if ($count > Utils_RecordBrowserCommon::$options_limit) {
             $companies = array();
         } else {
             $companies = self::get_companies($crits);
             if (!is_array($default)) {
                 if ($default != '') {
                     $default = array($default);
                 } else {
                     $default = array();
                 }
             }
             $ext_rec = array_flip($default);
             foreach ($companies as $v) {
                 $comp[$v['id']] = $v['company_name'];
                 unset($ext_rec[$v['id']]);
             }
             foreach ($ext_rec as $k => $v) {
                 $c = CRM_ContactsCommon::get_company($k);
                 $comp[$k] = $c['company_name'];
             }
             natcasesort($comp);
             $key = '';
             if ($no_company_option) {
                 $comp = array('' => '[' . __('w/o company') . ']') + $comp;
                 $key = -1;
             }
             if ($desc['type'] !== 'multiselect') {
                 $comp = array($key => '---') + $comp;
             }
         }
         $label = Utils_RecordBrowserCommon::get_field_tooltip($label, $desc['type'], 'company', $crits);
         if ($count > Utils_RecordBrowserCommon::$options_limit) {
             $callback = array('CRM_ContactsCommon', 'display_company');
             if ($desc['type'] !== 'multiselect') {
                 $form->addElement('autoselect', $field, $label, array(), array(array('CRM_ContactsCommon', 'autoselect_company_suggestbox'), array($crits, $callback)), $callback, array('id' => $field));
             } else {
                 $form->addElement('automulti', $field, $label, array('CRM_ContactsCommon', 'autoselect_company_suggestbox'), array($crits, $callback), $callback);
             }
             //                  $form->addElement($desc['type'], $field, $label, $comp, array('id'=>$field));
         } else {
             $form->addElement($desc['type'], $field, $label, $comp, array('id' => $field));
         }
         if ($mode !== 'add') {
             $form->setDefaults(array($field => $default));
         }
     } else {
         /*$def = '';
           $first = true;
           if (is_numeric($default) || is_array($default)) {
               if (!is_array($default)) $default = array($default);
               foreach($default as $k=>$v){
                   if ($v=='') break;
                   if ($first) $first = false;
                   else $def .= '<br>';
                   $def .= Utils_RecordBrowserCommon::no_wrap(Utils_RecordBrowserCommon::create_linked_label('company', 'Company Name', $v));
               }
           }
           if (!$def)  $def = '---';
           $form->setDefaults(array($field=>$def));*/
         if (isset($display_callbacks[$desc['name']])) {
             $callback = $display_callbacks[$desc['name']];
         } else {
             $callback = array('CRM_ContactsCommon', 'display_company');
         }
         //            trigger_error(print_r($rb->record,true),E_USER_ERROR);
         $form->addElement('static', $field, $label, call_user_func($callback, array('company' => $default), false, array('id' => 'company')));
     }
 }