Ejemplo n.º 1
0
 public function body()
 {
     ob_start();
     //create default module form
     print '<div class="title">Select modules to disable</div>';
     print 'Selected modules will be marked as not installed but uninstall methods will not be called. Any database tables and other modifications made by modules\' install methods will not be reverted.<br><br>';
     print 'To uninstall module please use Modules Administration in Application.';
     print '<hr/><br/>';
     $form = new HTML_QuickForm('modulesform', 'post', $_SERVER['PHP_SELF'] . '?' . http_build_query($_GET), '', null, true);
     $states = array(ModuleManager::MODULE_ENABLED => 'Active', ModuleManager::MODULE_DISABLED => 'Inactive');
     $modules = DB::GetAssoc('SELECT * FROM modules ORDER BY state, name');
     foreach ($modules as $m) {
         $name = $m['name'];
         $state = isset($m['state']) ? $m['state'] : ModuleManager::MODULE_ENABLED;
         if ($state == ModuleManager::MODULE_NOT_FOUND) {
             $state = ModuleManager::MODULE_DISABLED;
         }
         $form->addElement('select', $name, $name, $states);
         $form->setDefaults(array($name => $state));
     }
     $form->addElement('button', 'submit_button', 'Save', array('class' => 'button', 'onclick' => 'if(confirm("Are you sure?")) document.modulesform.submit();'));
     //validation or display
     if ($form->validate()) {
         //uninstall
         $vals = $form->exportValues();
         foreach ($vals as $k => $v) {
             if (isset($modules[$k]['state']) && $modules[$k]['state'] != $v) {
                 ModuleManager::set_module_state($k, $v);
             }
         }
     }
     $form->display();
     return ob_get_clean();
 }
Ejemplo n.º 2
0
 public static function get_all($start, $end, $filter = null)
 {
     if ($filter === null) {
         $filter = self::$filter;
     }
     $custom_handlers = DB::GetAssoc('SELECT id, handler_callback FROM crm_calendar_custom_events_handlers');
     $result = array();
     if (self::$events_handlers === null) {
         self::$events_handlers = array_keys($custom_handlers);
     }
     $count = 0;
     foreach (self::$events_handlers as $handler) {
         $callback = explode('::', $custom_handlers[$handler]);
         $result_ext = call_user_func($callback, 'get_all', $start, $end, $filter);
         foreach ($result_ext as $v) {
             if ($v !== null) {
                 $v['id'] = $handler . '#' . $v['id'];
                 $v['custom_agenda_col_0'] = isset($v['type']) ? $v['type'] : '---';
                 if (isset($v['description'])) {
                     $v['custom_agenda_col_1'] = $v['description'];
                 }
                 if (isset($v['employees'])) {
                     $emps = array();
                     if (is_array($v['employees'])) {
                         foreach ($v['employees'] as $e) {
                             $emps[] = CRM_ContactsCommon::contact_format_no_company($e);
                         }
                     }
                     $v['custom_agenda_col_2'] = implode('<br>', $emps);
                 }
                 if (isset($v['customers'])) {
                     $cuss = array();
                     if (is_array($v['customers'])) {
                         foreach ($v['customers'] as $c) {
                             $cuss[] = CRM_ContactsCommon::display_company_contact(array('customers' => $c), true, array('id' => 'customers'));
                         }
                     }
                     $v['custom_agenda_col_3'] = implode('<br>', $cuss);
                 }
                 $result[] = $v;
                 $count++;
                 if ($count == CRM_CalendarCommon::$events_limit) {
                     break;
                 }
             }
         }
         if ($count == CRM_CalendarCommon::$events_limit) {
             break;
         }
     }
     if ($count == CRM_CalendarCommon::$events_limit) {
         print '<b>There were too many events to display on the Calendar, please change CRM Filter</b>';
     }
     return $result;
 }
Ejemplo n.º 3
0
function rb_csv_export_format_currency_value($v, $symbol)
{
    static $currency_decimal_signs = null;
    static $currency_thou_signs;
    if ($currency_decimal_signs === null) {
        $currency_decimal_signs = DB::GetAssoc('SELECT symbol, decimal_sign FROM utils_currency');
        $currency_thou_signs = DB::GetAssoc('SELECT symbol, thousand_sign FROM utils_currency');
    }
    $v = str_replace($currency_thou_signs[$symbol], '', $v);
    $v = str_replace($currency_decimal_signs[$symbol], '.', $v);
    return $v;
}
Ejemplo n.º 4
0
 public static function menu()
 {
     $tabs = DB::GetAssoc('SELECT menu, tab FROM recordbrowser_custom_recordsets WHERE active=1');
     $result = array();
     foreach ($tabs as $k => $v) {
         if (!$k) {
             continue;
         }
         if (!Utils_RecordBrowserCommon::get_access($v, 'browse')) {
             continue;
         }
         $k = explode(self::$sep, $k);
         $menu = self::build_menu($k, array('tab' => $v));
         $result = array_merge_recursive($menu, $result);
     }
     return $result;
 }
Ejemplo n.º 5
0
 public static function set_profile($prof)
 {
     if (preg_match('/^c([0-9,]+)$/', $prof, $reqs)) {
         $ret = $reqs[1];
         if (strpos($ret, ',') === false) {
             $desc = CRM_ContactsCommon::contact_format_no_company($ret, true);
         } else {
             $desc = __('Custom filter');
         }
     } elseif (is_numeric($prof)) {
         $cids = DB::GetAssoc('SELECT contact_id, contact_id FROM crm_filters_contacts');
         $c = DB::GetCol('SELECT p.contact_id FROM crm_filters_contacts p WHERE p.group_id=%d', array($prof));
         if ($c) {
             $ret = implode(',', $c);
         } else {
             $ret = '-1';
         }
         $desc = DB::GetOne('SELECT name FROM crm_filters_group WHERE id=%d', array($prof));
     } elseif ($prof == 'my') {
         $ret = CRM_FiltersCommon::get_my_profile();
         $desc = __('My records');
     } else {
         //all and undefined
         $ret = '';
         /*$contacts = Utils_RecordBrowserCommon::get_records('contact', array(), array(), array('last_name'=>'ASC'));
         		$contacts_select = array();
         		foreach($contacts as $v)
         			$contacts_select[] = $v['id'];
         		if($contacts_select)
         			$ret = implode(',',$contacts_select);
         		else
         			$ret = '-1';*/
         $desc = __('All records');
     }
     //		$this->set_module_variable('profile',$ret);
     $_SESSION['client']['filter_' . Acl::get_user()]['value'] = $ret;
     $_SESSION['client']['filter_' . Acl::get_user()]['desc'] = $desc;
     location(array());
 }
Ejemplo n.º 6
0
 public static function user_search($search = null)
 {
     $myid = Base_AclCommon::get_user();
     if (Base_User_SettingsCommon::get('Apps_Shoutbox', 'enable_im')) {
         $adm = Base_User_SettingsCommon::get_admin('Apps_Shoutbox', 'enable_im');
         if (ModuleManager::is_installed('CRM_Contacts') >= 0) {
             $emps = DB::GetAssoc('SELECT l.id,' . DB::ifelse('cd.f_last_name!=\'\'', DB::concat('cd.f_last_name', DB::qstr(' '), 'cd.f_first_name'), 'l.login') . ' as name FROM user_login l LEFT JOIN contact_data_1 cd ON (cd.f_login=l.id AND cd.active=1) LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND (cd.f_first_name ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ' OR cd.f_last_name ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ') ORDER BY name', array($myid, serialize(1), $search, $search));
         } else {
             $emps = DB::GetAssoc('SELECT l.id,l.login FROM user_login l LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND l.login ' . DB::like() . ' ' . DB::concat(DB::qstr("%%"), "%s", DB::qstr("%%")) . ' ORDER BY l.login', array($myid, serialize(1), $search));
         }
     } else {
         $emps = array();
     }
     if (ModuleManager::is_installed('Tools_WhoIsOnline') >= 0) {
         $online = Tools_WhoIsOnlineCommon::get_ids();
         foreach ($online as $id) {
             if (isset($emps[$id])) {
                 $emps[$id] = '* ' . $emps[$id];
             }
         }
     }
     return $emps;
 }
Ejemplo n.º 7
0
 public static function get_access($module, $section = '', $force_check = false)
 {
     if (!$force_check && Base_AclCommon::i_am_sa()) {
         return true;
     }
     static $cache = array();
     if (!isset($cache[$module])) {
         $cache[$module] = array();
         $ret = DB::GetAssoc('SELECT section, allow FROM base_admin_access WHERE module=%s', array($module));
         $defaults = array('' => 1);
         if (class_exists($module . 'Common') && method_exists($module . 'Common', 'admin_access_levels')) {
             $raws = call_user_func(array($module . 'Common', 'admin_access_levels'));
             if ($raws == false) {
                 $defaults[''] = $raws;
             } else {
                 $defaults[''] = 1;
                 if (is_array($raws)) {
                     foreach ($raws as $s => $v) {
                         if (isset($v['default'])) {
                             $defaults[$s] = $v['default'];
                         } else {
                             $defaults[$s] = 0;
                         }
                     }
                 }
             }
         }
         foreach ($defaults as $s => $v) {
             if (isset($ret[$s])) {
                 $cache[$module][$s] = $ret[$s];
             } else {
                 $cache[$module][$s] = $v;
             }
         }
     }
     return $cache[$module][$section];
 }
Ejemplo n.º 8
0
	/**
	 * Returns common data array.
	 *
	 * @param string array name
	 * @param boolean order by key instead of value
	 * @return mixed returns an array if such array exists, false otherwise
	 */
	public static function get_array($name, $order_by_key=false, $readinfo=false, $silent=false){
		static $cache;
		if(isset($cache[$name][$order_by_key][$readinfo]))
			return $cache[$name][$order_by_key][$readinfo];
		$id = self::get_id($name);
		if($id===false)
			if ($silent) return null;
			else trigger_error('Invalid CommonData::get_array() request: '.$name,E_USER_ERROR);
		if($order_by_key)
			$order_by = 'akey ASC';
		else
			$order_by = 'value ASC';
		if($readinfo)
			$ret = DB::GetAssoc('SELECT akey, value, readonly FROM utils_commondata_tree WHERE parent_id=%d ORDER BY '.$order_by,array($id),true);
		else 
			$ret = DB::GetAssoc('SELECT akey, value FROM utils_commondata_tree WHERE parent_id=%d ORDER BY '.$order_by,array($id));
		$cache[$name][$order_by_key][$readinfo] = $ret;
		return $ret;
	}
Ejemplo n.º 9
0
 /**
  * Returns common data array.
  *
  * @param string array name
  * @param boolean order by key instead of value
  * @return mixed returns an array if such array exists, false otherwise
  */
 public static function get_array($name, $order_by_position = false, $readinfo = false, $silent = false)
 {
     static $cache;
     if (isset($cache[$name][$order_by_position][$readinfo])) {
         return $cache[$name][$order_by_position][$readinfo];
     }
     $id = self::get_id($name);
     if ($id === false) {
         if ($silent) {
             return null;
         } else {
             trigger_error('Invalid CommonData::get_array() request: ' . $name, E_USER_ERROR);
         }
     }
     if ($order_by_position) {
         $order_by = $order_by_position === 'key' ? 'akey ASC' : 'position ASC';
     } else {
         $order_by = 'value ASC';
     }
     if ($readinfo) {
         $ret = DB::GetAssoc('SELECT akey, value, readonly, position, id FROM utils_commondata_tree WHERE parent_id=%d ORDER BY ' . $order_by, array($id), true);
     } else {
         $ret = DB::GetAssoc('SELECT akey, value FROM utils_commondata_tree WHERE parent_id=%d ORDER BY ' . $order_by, array($id));
     }
     if ($order_by_position === 'key') {
         ksort($ret);
     }
     $cache[$name][$order_by_position][$readinfo] = $ret;
     return $ret;
 }
Ejemplo n.º 10
0
define('READ_ONLY_SESSION', true);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Acl::is_user()) {
    die('Not logged in');
}
$rec = Utils_RecordBrowserCommon::get_record('rc_mails', $_GET['id']);
if (!$rec) {
    die('Invalid e-mail id.');
}
$access_fields = Utils_RecordBrowserCommon::get_access('rc_mails', 'view', $rec);
if (!isset($access_fields['body']) || !$access_fields['body']) {
    die('Access forbidden');
}
if (isset($_GET['field']) && $_GET['field'] == 'headers') {
    $html = Utils_RecordBrowserCommon::get_val('rc_mails', 'headers_data', $rec, false, null);
} else {
    $html = $rec['body'];
}
if (!$html) {
    die('Invalid e-mail id.');
}
$images = DB::GetAssoc('SELECT mime_id,name FROM rc_mails_attachments WHERE mail_id=%d AND attachment=1 AND type ' . DB::like() . ' %s', array($_GET['id'], 'image/%'));
foreach ($images as $k => &$n) {
    $n = '<img src="get.php?' . http_build_query(array('mime_id' => $k, 'mail_id' => $_GET['id'])) . '" onload="fix_height();"/><br />';
}
$html = str_ireplace('<img ', '<img onload="fix_height();" ', $html);
$html = str_replace('__MAIL_ID__', $_GET['id'], $html);
$html = preg_replace("/<a([^>]*)>(.*)<\\/a>/i", '<a$1 target="_blank">$2</a>', $html);
$html = '<html>' . '<head><meta http-equiv=Content-Type content="text/html; charset=utf-8" />' . '<script type="text/javascript">function fix_height(){parent.$("rc_mail_body").height = Math.max(document.body.offsetHeight,document.body.scrollHeight)+30;}</script>' . '</head><body>' . $html . ($images ? '<hr />' . implode('<br />', $images) : '') . '<script type="text/javascript">fix_height();</script>' . '</body>' . '</html>';
print $html;
Ejemplo n.º 11
0
 public static function notification()
 {
     /*$methods = DB::GetAssoc('SELECT id,callback FROM utils_watchdog_category');
     		foreach ($methods as $k=>$v) { 
     			$methods[$k] = explode('::',$v);
     		}
             $time_sql = $time ? ' AND uwe.event_time > %T' : '';
     		$only_new = " AND last_seen_event<(SELECT MAX(id) FROM utils_watchdog_event AS uwe WHERE uwe.internal_id=uws.internal_id AND uwe.category_id=uws.category_id$time_sql)";
             $args = array(Acl::get_user());
             if ($time) {
                 $args[] = $time;
             }
             $records = DB::GetAll('SELECT internal_id,category_id,last_seen_event FROM utils_watchdog_subscription AS uws WHERE user_id=%d '.$only_new, $args);
     		$ret = array();
     		$tray = array();
             if ($records) {
                 $last_event_id = DB::GetOne('SELECT MAX(id) FROM utils_watchdog_event');
                 foreach ($records as $v) {
                     $changes = Utils_WatchdogCommon::check_if_notified($v['category_id'], $v['internal_id']);
                     if (!is_array($changes)) $changes = array();
                     $data = call_user_func($methods[$v['category_id']], $v['internal_id'], $changes, false);
                     if ($data==null) continue;
     
                     $msg = __("You've got unread notifications");
                     $ret['watchdog_'. $last_event_id] = '<b>'.__('Watchdog - %s', array($msg)).'</b> ';
                     $tray['watchdog_' . $last_event_id] = array('title'=>__('Watchdog'), 'body'=>$msg);
                     break;
                 }
             }*/
     $ret = array();
     $tray = array();
     $methods = DB::GetAssoc('SELECT id,callback FROM utils_watchdog_category');
     $only_new = ' AND last_seen_event<(SELECT MAX(id) FROM utils_watchdog_event AS uwe WHERE uwe.internal_id=uws.internal_id AND uwe.category_id=uws.category_id)';
     $records = DB::GetAll('SELECT internal_id,category_id FROM utils_watchdog_subscription AS uws WHERE user_id=%d ' . $only_new, array(Acl::get_user()));
     foreach ($records as $rec_key => $w) {
         $k = $w['internal_id'];
         $v = $w['category_id'];
         $changes = Utils_WatchdogCommon::check_if_notified($v, $k);
         if (!is_array($changes)) {
             $changes = array();
         }
         $data = call_user_func($methods[$v], $k, $changes);
         if ($data == null) {
             // mark events as seen when user can't see them
             Utils_WatchdogCommon::notified($v, $k);
             unset($records[$rec_key]);
             continue;
         }
         $ret['watchdog_' . $v . '_' . $k] = '<b>' . __('Watchdog - %s: %s', array($data['category'], $data['title'])) . '</b>' . (isset($data['events']) ? '<br />' . $data['events'] : '');
         $tray['watchdog_' . $v . '_' . $k] = array('title' => __('Watchdog - %s', array($data['category'])), 'body' => $data['title']);
     }
     return array('notifications' => $ret, 'tray' => $tray);
 }
Ejemplo n.º 12
0
 public static function load_cache()
 {
     if (!isset(self::$cache)) {
         self::$cache = DB::GetAssoc('SELECT id,pos_before,symbol,decimals,code,thousand_sign,decimal_sign FROM utils_currency');
     }
 }
Ejemplo n.º 13
0
	private function permissions_get_field_values($field, $in_depth=true) {
		static $all_fields = array();
		if (!isset($all_fields[$this->tab]))
			foreach ($this->table_rows as $k=>$v)
				$all_fields[$this->tab][$v['id']] = $k;
		$args = $this->table_rows[$all_fields[$this->tab][$field]];
		$arr = array(''=>'['.__('Empty').']');
		switch (true) {
			case $args['type']=='text' && $args['filter']:
				$arr_add = @DB::GetAssoc('SELECT f_'.$args['id'].', f_'.$args['id'].' FROM '.$this->tab.'_data_1 GROUP BY f_'.$args['id'].' ORDER BY count(*) DESC LIMIT 20');
				if($arr_add) $arr += $arr_add;
				break;
			case $args['commondata']:
				$array_id = is_array($args['param']) ? $args['param']['array_id'] : $args['ref_table'];
				if (strpos($array_id, '::')===false) 
					$arr = $arr + Utils_CommonDataCommon::get_translated_array($array_id, is_array($args['param'])?$args['param']['order_by_key']:false);
				break;
			case $this->tab=='contact' && $field=='login' ||
				 $this->tab=='rc_accounts' && $field=='epesi_user': // just a quickfix, better solution will be needed
				$arr = $arr + array('USER_ID'=>__('User Login'));
				break;
			case $args['type']=='date' || $args['type']=='timestamp':
				$arr = $arr + Utils_RecordBrowserCommon::$date_values;
				break;
			case ($args['type']=='multiselect' || $args['type']=='select') && (!isset($args['ref_table']) || !$args['ref_table']):
				$arr = $arr + array('USER'=>__('User Contact'));
				$arr = $arr + array('USER_COMPANY'=>__('User Company'));
				break;
			case $args['type']=='checkbox':
				$arr = array('1'=>__('Yes'),'0'=>__('No'));
				break;
			case ($args['type']=='select' || $args['type']=='multiselect') && isset($args['ref_table']):
				if ($args['ref_table']=='contact') $arr = $arr + array('USER'=>__('User Contact'));
				if ($args['ref_table']=='company') $arr = $arr + array('USER_COMPANY'=>__('User Company'));
				if (!$in_depth) continue;

				$last_tab = $this->tab;
                $tabs = explode(',', $args['ref_table']);
                if (count($tabs) != 1) break;
                $one_tab = reset($tabs);
                if ($one_tab != '__RECORDSETS__'
                        && Utils_RecordBrowserCommon::check_table_name($one_tab, false, false)) {
                    $this->tab = $one_tab;
                    $this->init();
                    if (!isset($all_fields[$this->tab]))
                        foreach ($this->table_rows as $k=>$v)
                            $all_fields[$this->tab][$v['id']] = $k;


                    foreach ($all_fields[$this->tab] as $k=>$v) {
                        if ($this->table_rows[$v]['type']=='calculated' || $this->table_rows[$v]['type']=='hidden') unset($all_fields[$this->tab][$k]);
                        else {
                            $arr2 = $this->permissions_get_field_values($k, false, $this->tab);
                            foreach ($arr2 as $k2=>$v2)
                                $arr2[$k2] = '"'.$k2.'":"'.$v2.'"';
                            eval_js('utils_recordbrowser__field_sub_values["'.$field.'__'.$k.'"] = {'.implode(',',$arr2).'};');
                        }
                    }
                    foreach ($all_fields[$this->tab] as $k=>$v) {
                        $arr[$k] = __(' records with %s set to ', array(_V($v)));
                    }
                }

				$this->tab = $last_tab;
				$this->init();
				break;
		}
		return $arr;
	}
Ejemplo n.º 14
0
 /**
  * Get downloaded modules list.
  * Array keys are 'module_id', 'version', 'file' and 'module_license_id'
  * @return associative array of data. Key is module id.
  */
 public static function get_downloaded_modules()
 {
     $records = DB::GetAssoc('SELECT * FROM epesi_store_modules');
     return $records;
 }
Ejemplo n.º 15
0
 public function chat($big = false, $uid = null)
 {
     $to =& $this->get_module_variable('to', "all");
     eval_js('shoutbox_uid="' . $to . '"');
     if (Base_AclCommon::is_user()) {
         //initialize HTML_QuickForm
         $qf = $this->init_module(Libs_QuickForm::module_name());
         /*            $myid = Base_AclCommon::get_user();
                 	if(Base_User_SettingsCommon::get('Apps_Shoutbox','enable_im')) {
                 	    $adm = Base_User_SettingsCommon::get_admin('Apps_Shoutbox','enable_im');
                 	    if(ModuleManager::is_installed('CRM_Contacts')>=0) {
                     	    $emps = DB::GetAssoc('SELECT l.id,IF(cd.f_last_name!=\'\',CONCAT(cd.f_last_name,\' \',cd.f_first_name,\' (\',l.login,\')\'),l.login) as name FROM user_login l LEFT JOIN contact_data_1 cd ON (cd.f_login=l.id AND cd.active=1) LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is '.($adm?'':'not ').'null) ORDER BY name',array($myid,serialize(1)));			    
         		        } else
             		        $emps = DB::GetAssoc('SELECT l.id,l.login FROM user_login l LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is '.($adm?'':'not ').'null) ORDER BY l.login',array($myid,serialize(1)));
             		} else $emps = array();
             		if(ModuleManager::is_installed('Tools_WhoIsOnline')>=0) {
             		    $online = Tools_WhoIsOnlineCommon::get_ids();
             		    foreach($online as $id) {
             		        if(isset($emps[$id])) 
             		            $emps[$id] = '* '.$emps[$id] ;
             		    }
             		}
                		$qf->addElement('select','to',__('To'),array('all'=>'['.__('All').']')+$emps,array('id'=>'shoutbox_to'.($big?'_big':''),'onChange'=>'shoutbox_uid=this.value;shoutbox_refresh'.($big?'_big':'').'()'));*/
         $myid = Base_AclCommon::get_user();
         if (Base_User_SettingsCommon::get('Apps_Shoutbox', 'enable_im') && ModuleManager::is_installed('Tools_WhoIsOnline') >= 0) {
             $adm = Base_User_SettingsCommon::get_admin('Apps_Shoutbox', 'enable_im');
             $online = Tools_WhoIsOnlineCommon::get_ids();
             if ($online) {
                 if (ModuleManager::is_installed('CRM_Contacts') >= 0) {
                     $emps = DB::GetAssoc('SELECT l.id,' . DB::Concat(DB::qstr("* "), DB::ifelse('cd.f_last_name!=\'\'', DB::concat('cd.f_last_name', DB::qstr(' '), 'cd.f_first_name', DB::qstr(' ('), 'l.login', DB::qstr(')')), 'l.login')) . ' as name FROM user_login l LEFT JOIN contact_data_1 cd ON (cd.f_login=l.id AND cd.active=1) LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND l.id IN (' . implode(',', $online) . ') ORDER BY name', array($myid, serialize(1)));
                 } else {
                     $emps = DB::GetAssoc('SELECT l.id,' . DB::Concat(DB::qstr("* "), 'l.login') . ' FROM user_login l LEFT JOIN base_user_settings us ON (us.user_login_id=l.id AND module=\'Apps_Shoutbox\' AND variable=\'enable_im\') WHERE l.active=1 AND l.id!=%d AND (us.value=%s OR us.value is ' . ($adm ? '' : 'not ') . 'null) AND l.id IN (' . implode(',', $online) . ') ORDER BY l.login', array($myid, serialize(1)));
                 }
             } else {
                 $emps = array();
             }
         } else {
             $emps = array();
         }
         $e = $qf->addElement('autoselect', 'shoutbox_to', __('To'), array('all' => '[' . __('All') . ']') + $emps, array(array($this->get_type() . 'Common', 'user_search'), array()), array($this->get_type() . 'Common', 'user_format'));
         $e->setAttribute('id', 'shoutbox_to' . ($big ? '_big' : ''));
         $e->setAttribute('onChange', 'shoutbox_uid=this.value;shoutbox_refresh' . ($big ? '_big' : '') . '()');
         if (!Base_User_SettingsCommon::get('Apps_Shoutbox', 'enable_im')) {
             $qf->freeze(array('shoutbox_to'));
         }
         //create text box
         $qf->addElement($big ? 'textarea' : 'textarea', 'post', __('Message'), 'class="border_radius_6px" id="shoutbox_text' . ($big ? '_big' : '') . '"');
         $qf->addRule('post', __('Field required'), 'required');
         //create submit button
         $qf->addElement('submit', 'submit_button', __('Send'), 'id="shoutbox_button' . ($big ? '_big' : '') . '"');
         //add it
         $qf->setRequiredNote(null);
         $qf->setDefaults(array('shoutbox_to' => $to));
         $theme = $this->init_module(Base_Theme::module_name());
         $qf->assign_theme('form', $theme);
         //confirm when sending messages to all
         eval_js("jq('#shoutbox_button, #shoutbox_button_big').click(function() {\n      \t\t\t\t\tvar submit = true;\n\t\t    \t\t\tif (jq('#shoutbox_to').val() == 'all' && !confirm('" . __('Send message to all?') . "')) {\n         \t\t\t\t\tsubmit = false;\n      \t\t\t\t\t}\n\t\t    \n\t\t    \t\t\treturn submit;\t\t    \t\t\t\n\t\t\t\t\t});");
         //if submited
         if ($qf->validate()) {
             //get post group
             $msg = $qf->exportValue('post');
             $to = $qf->exportValue('shoutbox_to');
             //get msg from post group
             $msg = Utils_BBCodeCommon::optimize($msg);
             //get logged user id
             $user_id = Base_AclCommon::get_user();
             //clear text box and focus it
             eval_js('$(\'shoutbox_text' . ($big ? '_big' : '') . '\').value=\'\';focus_by_id(\'shoutbox_text' . ($big ? '_big' : '') . '\');shoutbox_uid="' . $to . '"');
             //insert to db
             DB::Execute('INSERT INTO apps_shoutbox_messages(message,base_user_login_id,to_user_login_id) VALUES(%s,%d,%d)', array(htmlspecialchars($msg, ENT_QUOTES, 'UTF-8'), $user_id, is_numeric($to) ? $to : null));
         }
     } else {
         print __('Please log in to post message') . '<br>';
         return;
     }
     $theme->assign('board', '<div id=\'shoutbox_board' . ($big ? '_big' : '') . '\'></div>');
     $theme->assign('header', __('Shoutbox'));
     $theme->display('chat_form' . ($big ? '_big' : ''));
     //if shoutbox is diplayed, call myFunctions->refresh from refresh.php file every 5s
     eval_js_once('shoutbox_refresh' . ($big ? '_big' : '') . ' = function(){if(!$(\'shoutbox_board' . ($big ? '_big' : '') . '\')) return;' . 'new Ajax.Updater(\'shoutbox_board' . ($big ? '_big' : '') . '\',\'modules/Apps/Shoutbox/refresh.php\',{method:\'get\', parameters: { uid: shoutbox_uid }});' . '};setInterval(\'shoutbox_refresh' . ($big ? '_big' : '') . '()\',' . ($big ? '10000' : '30000') . ')');
     eval_js('shoutbox_refresh' . ($big ? '_big' : '') . '()');
 }
Ejemplo n.º 16
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;
    }
Ejemplo n.º 17
0
 public function configure_applet($id, $mod, &$ok = null)
 {
     $default_dash = $this->get_module_variable('default');
     if (!$default_dash && !Base_DashboardCommon::has_permission_to_manage_applets()) {
         return;
     }
     if ($this->is_back()) {
         $ok = false;
         return false;
     }
     $sett_fn = array($mod . 'Common', 'applet_settings');
     $is_conf = is_callable($sett_fn);
     $fc = $this->get_module_variable('first_conf');
     if (!$is_conf && $fc) {
         $ok = true;
         return false;
     }
     $f = $this->init_module(Libs_QuickForm::module_name(), __('Saving settings'), 'settings');
     $caption = call_user_func(array($mod . 'Common', 'applet_caption'));
     if ($is_conf) {
         $f->addElement('header', null, __('%s settings', array($caption)));
         $menu = call_user_func($sett_fn);
         if (is_array($menu)) {
             $this->add_module_settings_to_form($menu, $f, $id, $mod);
         } else {
             trigger_error('Invalid applet settings function: ' . $mod, E_USER_ERROR);
         }
     }
     $f->addElement('header', null, $caption . ' ' . __('display settings'));
     $color = Base_DashboardCommon::get_available_colors();
     $color[0] = __('Default') . ': ' . $color[0]['label'];
     for ($k = 1; $k < count($color); $k++) {
         $color[$k] = '&bull; ' . $color[$k]['label'];
     }
     $f->addElement('select', '__color', __('Color'), $color, array('style' => 'width: 100%;'));
     $table_tabs = 'base_dashboard_' . ($default_dash ? 'default_' : '') . 'tabs';
     $table_applets = 'base_dashboard_' . ($default_dash ? 'default_' : '') . 'applets';
     $tabs = DB::GetAssoc('SELECT id,name FROM ' . $table_tabs . ($default_dash ? '' : ' WHERE user_login_id=' . Base_AclCommon::get_user()));
     $f->addElement('select', '__tab', __('Tab'), $tabs);
     $dfs = DB::GetRow('SELECT tab,color FROM ' . $table_applets . ' WHERE id=%d', array($id));
     $f->setDefaults(array('__tab' => $dfs['tab'], '__color' => $dfs['color']));
     if ($f->validate()) {
         //$f->process(array(& $this, 'submit_settings'));
         $submited = $f->exportValues();
         DB::Execute('UPDATE ' . $table_applets . ' SET tab=%d WHERE id=%d', array($submited['__tab'], $id));
         DB::Execute('UPDATE ' . $table_applets . ' SET color=%d WHERE id=%d', array($submited['__color'], $id));
         $defaults = $this->get_default_values($mod);
         $old = $this->get_values($id, $mod);
         foreach ($defaults as $name => $def_value) {
             if (!isset($submited[$name])) {
                 $submited[$name] = 0;
             }
             if ($submited[$name] != $old[$name]) {
                 if ($this->get_module_variable('default')) {
                     if ($submited[$name] == $def_value) {
                         DB::Execute('DELETE FROM base_dashboard_default_settings WHERE applet_id=%d AND name=%s', array($id, $name));
                     } else {
                         DB::Replace('base_dashboard_default_settings', array('applet_id' => $id, 'name' => $name, 'value' => $submited[$name]), array('applet_id', 'name'), true);
                     }
                 } else {
                     if ($submited[$name] == $def_value) {
                         DB::Execute('DELETE FROM base_dashboard_settings WHERE applet_id=%d AND name=%s', array($id, $name));
                     } else {
                         DB::Replace('base_dashboard_settings', array('applet_id' => $id, 'name' => $name, 'value' => $submited[$name]), array('applet_id', 'name'), true);
                     }
                 }
             }
         }
         $ok = true;
         self::$settings_cache = null;
         return false;
     }
     $ok = null;
     $f->display();
     Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     Base_ActionBarCommon::add('save', __('Save'), $f->get_submit_form_href());
     Base_ActionBarCommon::add('settings', __('Restore Defaults'), 'onClick="' . $this->set_default_js . '" href="javascript:void(0)"');
     return true;
 }
Ejemplo n.º 18
0
 public function applet($conf, &$opts)
 {
     $categories = array();
     $methods = DB::GetAssoc('SELECT id,callback FROM utils_watchdog_category');
     foreach ($methods as $k => $v) {
         $methods[$k] = explode('::', $v);
         if (isset($conf['category_' . $k]) && $conf['category_' . $k] && is_numeric($k)) {
             $categories[] = $k;
         }
     }
     if (empty($categories)) {
         print __('No category selected');
         return;
     }
     $records_limit = isset($conf['records_limit']) ? $conf['records_limit'] : 15;
     if ($records_limit == '__all__') {
         $records_limit = null;
     }
     $header = array(array('name' => __('Cat.'), 'width' => 5), array('name' => __('Title'), 'width' => 15));
     if (count($categories) == 1) {
         $title = call_user_func($methods[$categories[0]]);
         $opts['title'] = __('Watchdog - %s', array($title['category']));
         $header = array(array('name' => __('Title')));
     } elseif (count($categories) == count($methods)) {
         $opts['title'] = __('Watchdog - All');
     } else {
         $opts['title'] = __('Watchdog - Selection');
     }
     $only_new = ' AND last_seen_event<(SELECT MAX(id) FROM utils_watchdog_event AS uwe WHERE uwe.internal_id=uws.internal_id AND uwe.category_id=uws.category_id)';
     $records = DB::GetAll('SELECT internal_id,category_id FROM utils_watchdog_subscription AS uws WHERE user_id=%d ' . $only_new . 'AND category_id IN (' . implode(',', $categories) . ')', array(Acl::get_user()));
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), 'subscriptions', 'subscriptions');
     $gb->set_table_columns($header);
     $something_to_purge = false;
     $count = 0;
     foreach ($records as $rec_key => $w) {
         $k = $w['internal_id'];
         $v = $w['category_id'];
         $changes = Utils_WatchdogCommon::check_if_notified($v, $k);
         if (!is_array($changes)) {
             $changes = array();
         }
         $data = call_user_func($methods[$v], $k, $changes);
         if ($data == null) {
             // mark events as seen when user can't see them
             Utils_WatchdogCommon::notified($v, $k);
             unset($records[$rec_key]);
             continue;
         }
         $gb_row = $gb->get_new_row();
         if (count($categories) == 1) {
             $gb_row->add_data($data['title']);
         } else {
             $gb_row->add_data($data['category'], $data['title']);
         }
         $gb_row->add_action(Utils_WatchdogCommon::get_confirm_change_subscr_href($v, $k), 'Stop Watching', __('Click to stop watching this record for changes'), Base_ThemeCommon::get_template_file(Utils_Watchdog::module_name(), 'watching_small_new_events.png'));
         $gb_row->add_action($data['view_href'], 'View');
         if ($only_new || Utils_WatchdogCommon::check_if_notified($v, $k) !== true) {
             $gb_row->set_attrs('name="watchdog_table_row_' . $v . '__' . $k . '"');
             load_js('modules/Utils/Watchdog/applet_mark_as_read.js');
             $gb_row->add_action('href="javascript:void(0);" onclick="watchdog_applet_mark_as_read(\'' . $v . '__' . $k . '\')"', 'Mark as Read', __('Mark as read'), Base_ThemeCommon::get_template_file(Utils_Watchdog::module_name(), 'mark_as_read.png'));
             $something_to_purge = true;
         }
         if (isset($data['events']) && $data['events']) {
             $gb_row->add_info($data['events'], true);
         }
         $count++;
         if ($records_limit && $count >= $records_limit) {
             break;
         }
     }
     $records_qty = count($records);
     if ($records_limit && $count < $records_qty) {
         print __('Displaying %s of %s records', array($count, $records_qty));
     }
     $this->set_module_variable('display_at_time', time());
     if ($something_to_purge) {
         $opts['actions'][] = '<a ' . Utils_TooltipCommon::open_tag_attrs(__('Mark all entries as read')) . ' ' . $this->create_confirm_callback_href(__('This will mark all entries in selected categories as read, are you sure you want to continue?'), array($this, 'purge_subscriptions_applet'), array($categories)) . '><img src="' . Base_ThemeCommon::get_template_file('Utils_Watchdog', 'purge.png') . '" border="0"></a>';
     }
     $this->display_module($gb);
 }
Ejemplo n.º 19
0
 public static function get_event_handlers()
 {
     $custom_events = DB::GetAssoc('SELECT id, group_name FROM crm_calendar_custom_events_handlers ORDER BY group_name');
     foreach ($custom_events as $k => $v) {
         $custom_events[$k] = _V($v);
     }
     // ****** Calendar Custom handler label
     return $custom_events;
 }
Ejemplo n.º 20
0
	public static function get_alarms($id) {
		return DB::GetAssoc('SELECT id, alert_on FROM utils_messenger_message WHERE page_id=%s', array(md5($id)));
	}
Ejemplo n.º 21
0
 public function applet($conf, &$opts)
 {
     $opts['go'] = true;
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'agendaX');
     $columns = array(array('name' => __('Start'), 'order' => 'e.starts', 'width' => 25, 'wrapmode' => 'nowrap'), array('name' => __('Title'), 'order' => 'e.title', 'width' => 50));
     $gb->set_table_columns($columns);
     $start = date('Y-m-d', time());
     $end = date('Y-m-d', time() + $conf['days'] * 24 * 60 * 60);
     $gb->set_default_order(array(__('Start') => 'ASC'));
     CRM_Calendar_EventCommon::$filter = '(' . CRM_FiltersCommon::get_my_profile() . ')';
     $data = array();
     Base_ThemeCommon::load_css('CRM_Calendar', 'agenda');
     $custom_events = DB::GetAssoc('SELECT id, handler_callback FROM crm_calendar_custom_events_handlers ORDER BY group_name');
     $ret = array();
     if (!empty($custom_events)) {
         $c = 0;
         foreach ($custom_events as $id => $cb) {
             if ($conf['events_handlers__' . $id]) {
                 $cb = explode('::', $cb);
                 if (!is_callable($cb)) {
                     continue;
                 }
                 $add = call_user_func($cb, 'get_all', $start, $end, CRM_Calendar_EventCommon::$filter);
                 foreach ($add as $v) {
                     $ret[str_pad($v['start'], 16, '0', STR_PAD_LEFT) . '__' . $c] = $v;
                     $c++;
                 }
             }
         }
     }
     ksort($ret);
     foreach ($ret as $row) {
         if (isset($row['status']) && $row['status'] == 'closed') {
             continue;
         }
         if (!isset($row['view_action'])) {
             $ex = Utils_CalendarCommon::process_event($row);
             $view_action = '<a ' . $this->create_callback_href(array($this, 'view_event'), $row['id']) . '>';
             $ev_id = explode('_', $row['id'], 2);
             $ev_id = $ev_id[0];
         } else {
             $tmp = Utils_CalendarCommon::process_event($row);
             $ex = $row;
             $ex['start'] = $tmp['start'];
             $view_action = '<a ' . $row['view_action'] . '>';
         }
         //////////////////////////
         // left column
         $date = $ex['start'];
         ///////////////////
         // right column
         $title = Utils_TooltipCommon::create($row['title'], $row['custom_tooltip']);
         $day = isset($row['timeless']) && $row['timeless'] ? $row['timeless'] : Base_RegionalSettingsCommon::time2reg($row['start'], false, true, true, false);
         if ($day < date('Y-m-d')) {
             $class = 'past';
         } elseif ($day == date('Y-m-d')) {
             $class = 'today';
         } elseif ($day == date('Y-m-d', strtotime('+1 day'))) {
             $class = 'tomorrow';
         } else {
             $class = 'other';
         }
         $gb_row = $gb->get_new_row();
         $gb_row->set_attrs('class="CRM_Calendar_applet__' . $class . '"');
         $gb_row->add_data(array('value' => $date, 'order_value' => isset($row['timeless']) && $row['timeless'] ? strtotime($row['timeless']) : $row['start']), array('value' => $view_action . $title . '</a>'));
     }
     $this->display_module($gb, array(false), 'automatic_display');
 }
Ejemplo n.º 22
0
 public static function search_categories()
 {
     $tabs = DB::GetAssoc('SELECT t.id,t.tab,t.search_include FROM recordbrowser_table_properties t WHERE t.search_include>0 AND t.id IN (SELECT DISTINCT m.tab_id FROM recordbrowser_words_map m)');
     $ret = array();
     foreach ($tabs as $tab_id => $tab) {
         $caption = self::get_caption($tab['tab']);
         if (!$caption) {
             continue;
         }
         $ret[$tab_id] = array('caption' => $caption, 'checked' => $tab['search_include'] == 1);
     }
     uasort($ret, create_function('$a,$b', 'return strnatcasecmp($a["caption"],$b["caption"]);'));
     return $ret;
 }
Ejemplo n.º 23
0
        die('Invalid token in URL - please go to Administrator Panel->Cron and copy valid cron URL.');
    }
}
require_once 'include.php';
$lock = DATA_DIR . '/cron.lock';
if (file_exists($lock) && filemtime($lock) > time() - 6 * 3600) {
    die;
}
register_shutdown_function(create_function('', '@unlink("' . $lock . '");'));
file_put_contents($lock, '');
set_time_limit(0);
ini_set('memory_limit', '512M');
ModuleManager::load_modules();
Base_AclCommon::set_sa_user();
$ret = ModuleManager::call_common_methods('cron');
$cron_last = DB::GetAssoc('SELECT func,last,running FROM cron ORDER BY last');
$cron_funcs_prior = array();
//array of outdated cron callbacks
$t = time();
foreach ($ret as $name => $obj) {
    if (!$obj) {
        continue;
    }
    if (is_array($obj)) {
        foreach ($obj as $func => $every) {
            if (!strpos($func, '::')) {
                $func = $name . 'Common::' . $func;
            }
            $func_md5 = md5($func);
            //if first cron run exists and it was executed in specified time or it keep running less then 24h - skip
            if (isset($cron_last[$func_md5]) && ($cron_last[$func_md5]['last'] > $t - $every * 60 || $cron_last[$func_md5]['running'] && $cron_last[$func_md5]['last'] > $t - min($every * 60 * 30, 24 * 60 * 60))) {
Ejemplo n.º 24
0
 public function edit($user_settings_nav = true)
 {
     if ($user_settings_nav) {
         Base_ActionBarCommon::add('back', __('Back'), $this->create_main_href('Base_User_Settings'));
     }
     Base_ActionBarCommon::add('add', __('Add preset'), $this->create_callback_href(array($this, 'edit_group')));
     $gb = $this->init_module('Utils/GenericBrowser', null, 'edit');
     $gb->set_table_columns(array(array('name' => __('Name'), 'width' => 20, 'order' => 'g.name'), array('name' => __('Description'), 'width' => 30, 'order' => 'g.description'), array('name' => __('Users in category'), 'width' => 50, 'order' => '')));
     $ret = DB::Execute('SELECT g.name,g.id,g.description FROM crm_filters_group g WHERE g.user_login_id=' . Acl::get_user());
     while ($row = $ret->FetchRow()) {
         $gb_row =& $gb->get_new_row();
         $gb_row->add_action($this->create_confirm_callback_href(__('Delete this group?'), array('CRM_Filters', 'delete_group'), $row['id']), 'Delete');
         $gb_row->add_action($this->create_callback_href(array($this, 'edit_group'), $row['id']), 'Edit');
         $cids = DB::GetAssoc('SELECT c.contact_id, c.contact_id FROM crm_filters_contacts c WHERE c.group_id=%d', array($row['id']));
         $users = array();
         foreach ($cids as $v) {
             $users[] = CRM_ContactsCommon::contact_format_no_company(CRM_ContactsCommon::get_contact($v), true);
         }
         $gb_row->add_data($row['name'], $row['description'], implode(', ', $users));
     }
     $this->display_module($gb);
     $qf = $this->init_module('Libs/QuickForm', null, 'default_filter');
     $qf->addElement('checkbox', 'show_all_contacts_in_filters', __('Show all contacts in Perspective selection'), null, array('onChange' => $qf->get_submit_form_js()));
     $qf->addElement('checkbox', 'show_only_users_in_filters', __('Show only users in Perspective selection'), null, array('onChange' => $qf->get_submit_form_js()));
     $qf->setDefaults(array('show_all_contacts_in_filters' => Base_User_SettingsCommon::get('CRM_Contacts', 'show_all_contacts_in_filters'), 'show_only_users_in_filters' => Base_User_SettingsCommon::get('CRM_Contacts', 'show_only_users_in_filters')));
     if ($qf->validate()) {
         $vals = $qf->exportValues();
         if (!isset($vals['show_all_contacts_in_filters'])) {
             $vals['show_all_contacts_in_filters'] = 0;
         }
         if (!isset($vals['show_only_users_in_filters'])) {
             $vals['show_only_users_in_filters'] = 0;
         }
         Base_User_SettingsCommon::save('CRM_Contacts', 'show_all_contacts_in_filters', $vals['show_all_contacts_in_filters']);
         Base_User_SettingsCommon::save('CRM_Contacts', 'show_only_users_in_filters', $vals['show_only_users_in_filters']);
     }
     $qf->display();
 }
<?php

defined("_VALID_ACCESS") || die('Direct access forbidden');
Utils_CommonDataCommon::extend_array('Contacts/Access', array('employee' => _M('Employee')));
$cmp = Variable::get('main_company', null);
if ($cmp) {
    set_time_limit(0);
    $conts = DB::GetAll('SELECT * FROM contact_data_1 WHERE f_company_name=%d OR f_related_companies ' . DB::like() . ' ' . DB::Concat(DB::qstr('\\_\\_'), DB::qstr($cmp), DB::qstr('\\_\\_')), array($cmp));
    foreach ($conts as $k => $v) {
        $v['access'] = Utils_RecordBrowserCommon::decode_multi($v['f_access']);
        $v['access'][] = 'employee';
        Utils_RecordBrowserCommon::update_record('contact', $v['id'], array('access' => $v['access']));
    }
    Variable::delete('main_company', false);
}
$tab = DB::GetAssoc('SELECT tab, tab FROM recordbrowser_table_properties');
foreach ($tab as $t) {
    DB::Execute('UPDATE ' . $t . '_access_clearance SET clearance=%s WHERE clearance=%s', array('ACCESS:employee', 'EMPLOYEE'));
}
Ejemplo n.º 26
0
 public function user_actions($r, $gb_row)
 {
     static $admin_levels = false;
     static $my_level = false;
     if ($admin_levels === false) {
         $admin_levels = DB::GetAssoc('SELECT id,admin FROM user_login');
     }
     if ($my_level === false) {
         $my_level = isset($admin_levels[Base_AclCommon::get_user()]) ? $admin_levels[Base_AclCommon::get_user()] : 0;
     }
     $mod = 'Base_User_Administrator';
     $log_as_user = Base_AdminCommon::get_access($mod, 'log_as_user');
     $log_as_admin = Base_AdminCommon::get_access($mod, 'log_as_admin');
     $user_level = isset($admin_levels[$r['login']]) ? $admin_levels[$r['login']] : 0;
     // 2 is superadmin, 1 admin, 0 user
     if ($my_level == 2 || $my_level == 1 && ($user_level == 0 && $log_as_user || $user_level == 1 && $log_as_admin)) {
         // contact is admin and I can login as admin
         if (Base_UserCommon::is_active($r['login'])) {
             $gb_row->add_action($this->create_callback_href(array($this, 'change_user_active_state'), array($r['login'], false)), 'Deactivate user', null, Base_ThemeCommon::get_template_file('Utils_GenericBrowser', 'active-on.png'));
             $gb_row->add_action(Module::create_href(array('log_as_user' => $r['login'])), 'Log as user', null, Base_ThemeCommon::get_template_file('Utils_GenericBrowser', 'restore.png'));
             // action!
             if (isset($_REQUEST['log_as_user']) && $_REQUEST['log_as_user'] == $r['login']) {
                 Acl::set_user($r['login'], true);
                 Epesi::redirect();
                 return;
             }
         } else {
             $gb_row->add_action($this->create_callback_href(array($this, 'change_user_active_state'), array($r['login'], true)), 'Activate user', null, Base_ThemeCommon::get_template_file('Utils_GenericBrowser', 'active-off.png'));
         }
     }
 }
Ejemplo n.º 27
0
 public static function QFfield_recordset(&$form, $field, $label, $mode, $default)
 {
     if ($mode == 'add' || $mode == 'edit') {
         $rss = DB::GetCol('SELECT f_recordset FROM task_related_data_1 WHERE active=1');
         // remove currently selected value
         $key = array_search($default, $rss);
         if ($key !== false) {
             unset($rss[$key]);
         }
         $tabs = DB::GetAssoc('SELECT tab, caption FROM recordbrowser_table_properties WHERE tab not in (\'' . implode('\',\'', $rss) . '\') AND tab not like "%_related"');
         foreach ($tabs as $k => $v) {
             $tabs[$k] = _V($v) . " ({$k})";
         }
         $form->addElement('select', $field, $label, $tabs, array('id' => $field));
         $form->addRule($field, 'Field required', 'required');
         if ($mode == 'edit') {
             $form->setDefaults(array($field => $default));
         }
     } else {
         $form->addElement('static', $field, $label);
         $form->setDefaults(array($field => $default));
     }
 }
Ejemplo n.º 28
0
 private static function load()
 {
     if (!isset(self::$variables)) {
         self::$variables = DB::GetAssoc("SELECT name,value FROM variables");
     }
 }
Ejemplo n.º 29
0
 public function attachments_addon($arg, $rb)
 {
     $m = $this->init_module('Utils/GenericBrowser', null, 'attachments');
     $attachments = DB::GetAssoc('SELECT mime_id,name FROM rc_mails_attachments WHERE mail_id=%d AND attachment=1', array($arg['id']));
     $data = array();
     foreach ($attachments as $k => &$n) {
         $filename = DATA_DIR . '/CRM_Roundcube/attachments/' . $arg['id'] . '/' . $k;
         $data[] = array('<a href="modules/CRM/Roundcube/get.php?' . http_build_query(array('mime_id' => $k, 'mail_id' => $arg['id'])) . '" target="_blank">' . $n . '</a>', file_exists($filename) ? filesize($filename) : '---');
     }
     $this->display_module($m, array(array(array('name' => 'Filename', 'search' => 1), array('name' => 'Size')), $data, false, null, array('Filename' => 'ASC')), 'simple_table');
 }
Ejemplo n.º 30
0
 public function detranslate_field_names($rset, &$fs)
 {
     Utils_RecordBrowserCommon::check_table_name($rset);
     $fields = DB::GetAssoc('SELECT field, field FROM ' . $rset . '_field WHERE type!=%s AND field!=%s AND type!=%s ORDER BY position', array('page_split', 'id', 'hidden'));
     foreach ($fields as $k => $f) {
         $fields[_V($f)] = $f;
     }
     // ****** RecordBrowser - field name
     $ret = array();
     foreach ($fs as $k => $f) {
         $f = trim($f);
         $fs[$k] = $f;
         if (isset($fields[$f]) && $f == $fields[$f]) {
             continue;
         }
         if (isset($fields[$f])) {
             $fs[$k] = $fields[$f];
             continue;
         }
         $ret['label_field'] = __('Field not found: %s', array($f));
     }
     return $ret;
 }