Example #1
0
 public function admin()
 {
     if ($this->is_back()) {
         if ($this->parent->get_type() == 'Base_Admin') {
             $this->parent->reset();
         } elseif (Base_BoxCommon::main_module_instance()->get_type() == $this->get_type()) {
             Base_BoxCommon::pop_main();
         }
         return;
     }
     Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     $gb = $this->init_module(Utils_GenericBrowser::module_name(), null, 'rb_custom');
     $gb->set_table_columns(array(array('name' => __('Table')), array('name' => __('Caption')), array('name' => __('Menu Entry'))));
     $tabs = DB::GetAll('SELECT * FROM recordbrowser_custom_recordsets ORDER BY tab ASC');
     foreach ($tabs as $t) {
         $gbr = $gb->get_new_row();
         if (!$t['active']) {
             $gbr->add_action($this->create_callback_href(array($this, 'set_active'), array($t['id'], true)), 'Activate', null, 'active-off');
         } else {
             $gbr->add_action($this->create_callback_href(array($this, 'set_active'), array($t['id'], false)), 'Deactivate', null, 'active-on');
         }
         $gbr->add_action($this->create_callback_href(array($this, 'edit_rset'), array($t['id'])), 'edit');
         $table_name = $t['tab'];
         $table_href = $this->create_callback_href(array($this, 'manage_recordset'), array($table_name));
         $gbr->add_data("<a {$table_href}>{$table_name}</a>", Utils_RecordBrowserCommon::get_caption($t['tab']), str_replace(Utils_RecordBrowser_CustomRecordsetsCommon::$sep, ' -> ', $t['menu']));
     }
     Base_ActionBarCommon::add('new', __('Create new'), $this->create_callback_href(array($this, 'edit_rset')));
     $this->display_module($gb);
 }
Example #2
0
 /**
  * Fetch all pending operations
  *
  * @return PendingOperation[]
  */
 public function GetPendingOperationList($object_type = null, $object_id = null)
 {
     // Domain operations
     if ($object_type && $object_id) {
         // XXX
         $arr = $this->DB->GetAll("\r\n\t\t\t\t\tSELECT p.* FROM pending_operations as p \r\n\t\t\t\t\tINNER JOIN domains as d ON (p.objectid = d.id AND p.objecttype = ?) \r\n\t\t\t\t\tWHERE d.TLD = ? AND p.objecttype = ? AND p.objectid = ?\r\n\t\t\t\t\t\r\n\t\t\t\t\tUNION\r\n\t\t\t\t\t\r\n\t\t\t\t\tSELECT p.* FROM pending_operations as p\r\n\t\t\t\t\tINNER JOIN contacts AS c ON (p.objectid = c.id AND p.objecttype = ?)\r\n\t\t\t\t\tWHERE (c.TLD = ? OR c.module_name = ?) AND p.objecttype = ? AND p.objectid = ?\r\n\t\t\t\t\t", array(self::OBJ_DOMAIN, $this->RegModule->Extension, $object_type, $object_id, self::OBJ_CONTACT, $this->RegModule->Extension, $this->RegModule->ModuleName, $object_type, $object_id));
     } else {
         $arr = $this->DB->GetAll("\r\n\t\t\t\t\tSELECT p.* FROM pending_operations as p \r\n\t\t\t\t\tINNER JOIN domains as d ON (p.objectid = d.id AND p.objecttype = ?) \r\n\t\t\t\t\tWHERE d.TLD = ?\r\n\t\t\t\t\t\r\n\t\t\t\t\tUNION\r\n\t\t\t\t\t\r\n\t\t\t\t\tSELECT p.* FROM pending_operations as p\r\n\t\t\t\t\tINNER JOIN contacts AS c ON (p.objectid = c.id AND p.objecttype = ?)\r\n\t\t\t\t\tWHERE (c.TLD = ? OR c.module_name = ?)\r\n\t\t\t\t\t", array(self::OBJ_DOMAIN, $this->RegModule->Extension, self::OBJ_CONTACT, $this->RegModule->Extension, $this->RegModule->ModuleName));
     }
     $ret = array();
     foreach ($arr as $row) {
         try {
             $op = new PendingOperation();
             $op->ID = $row['id'];
             $op->Type = $row['operation'];
             $op->InitDate = strtotime($row['dtbegin']);
             $op->RegistryOpId = $row['registry_opid'];
             $op->ObjectBefore = unserialize($row["object_before"]);
             $op->ObjectAfter = unserialize($row["object_after"]);
             if ($row['objecttype'] == self::OBJ_DOMAIN) {
                 $op->Object = $this->DBDomain->Load($row['objectid']);
             } else {
                 if ($row['objecttype'] == self::OBJ_CONTACT) {
                     $op->Object = $this->DBContact->Load($row['objectid']);
                 } else {
                     continue;
                 }
             }
             $ret[] = $op;
         } catch (Exception $e) {
             Log::Log('Fetch pending operation object failed: ' . $e->getMessage(), E_USER_ERROR);
         }
     }
     return $ret;
 }
Example #3
0
 public static function init()
 {
     self::$bbcodes = array();
     $bbcodes_raw = DB::GetAll('SELECT * FROM utils_bbcode');
     foreach ($bbcodes_raw as $v) {
         self::$bbcodes[$v['code']] = explode('::', $v['func']);
     }
 }
Example #4
0
 public function body()
 {
     if (!Base_AclCommon::i_am_user()) {
         print __('First log in to the system.');
         return;
     }
     $form = $this->init_module(Libs_QuickForm::module_name(), __('Saving settings'));
     //pass
     $form->addElement('header', null, __('Change password'));
     $form->addElement('html', '<tr><td colspan=2>' . __('Leave password boxes empty if you prefer your current password') . '</td></tr>');
     $form->addElement('password', 'new_pass', __('New password'));
     $form->addElement('password', 'new_pass_c', __('Confirm new password'));
     $form->addRule(array('new_pass', 'new_pass_c'), __('Your passwords don\'t match'), 'compare');
     $form->addRule('new_pass', __('Your password must be longer then 5 chars'), 'minlength', 6);
     //mail
     $form->addElement('header', null, __('Change e-mail'));
     $form->addElement('text', 'mail', __('New e-mail address'));
     $form->addRule('mail', __('Field required'), 'required');
     $form->addRule('mail', __('Invalid e-mail address'), 'email');
     //autologin
     $ret = DB::GetAll('SELECT autologin_id,description,last_log FROM user_autologin WHERE user_login_id=%d', array(Acl::get_user()));
     if ($ret) {
         $form->addElement('header', null, __('Delete autologin'));
     }
     foreach ($ret as $row) {
         $form->addElement('checkbox', 'delete_autologin[' . $row['autologin_id'] . ']', $row['description'], Base_RegionalSettingsCommon::time2reg($row['last_log']));
     }
     //confirmation
     $form->addElement('header', null, __('Confirmation'));
     $form->addElement('password', 'old_pass', __('Old password'));
     $form->registerRule('check_old_pass', 'callback', 'check_old_pass', $this);
     $form->addRule('old_pass', __('Old password incorrect'), 'check_old_pass');
     $form->addRule('old_pass', __('Field required'), 'required');
     if (Base_AclCommon::check_permission('Advanced User Settings')) {
         Base_ActionBarCommon::add('back', __('Back'), $this->create_main_href('Base_User_Settings'));
     }
     Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href());
     #$form->addElement('submit', 'submit_button', __('OK'));
     if ($form->validate_with_message('Setting saved', __('Problem encountered'))) {
         if ($form->process(array(&$this, 'submit_user_preferences'))) {
             if (Base_AclCommon::check_permission('Advanced User Settings')) {
                 Base_BoxCommon::location('Base_User_Settings');
             }
         }
     } else {
         //defaults
         $ret = DB::Execute('SELECT p.mail FROM user_password p  WHERE p.user_login_id=%d', Acl::get_user());
         if ($row = $ret->FetchRow()) {
             $form->setDefaults(array('mail' => $row[0]));
         }
         $form->display();
     }
 }
Example #5
0
 /**
  * Get first(by id) user that is super administrator and get it's first
  * and last name from crm_contacts
  *
  * This function uses DB query to get users and generally it should be
  * easier way to get super admin.
  *
  * @return array with keys admin_email, admin_first_name, admin_last_name
  */
 public static function get_possible_admin()
 {
     $users = DB::GetAll('select id, mail from user_login inner join user_password on user_login_id = id where admin=2');
     foreach ($users as $u) {
         $x = array('admin_email' => $u['mail']);
         if (ModuleManager::is_installed('CRM_Contacts') > -1) {
             $contact = CRM_ContactsCommon::get_contact_by_user_id($u['id']);
             if ($contact) {
                 $x['admin_first_name'] = $contact['first_name'];
                 $x['admin_last_name'] = $contact['last_name'];
             }
         }
         return $x;
     }
     return null;
 }
Example #6
0
 public function user_admin()
 {
     if ($this->is_back()) {
         if ($this->parent->parent->get_type() == 'Base_Admin') {
             $this->parent->parent->reset();
         } else {
             location(array());
         }
         return;
     }
     if (!Base_AclCommon::i_am_admin()) {
         return false;
     }
     Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     $this->rb = $this->init_module('Utils/RecordBrowser', 'contact', 'contact');
     $logins = DB::GetAll('SELECT * FROM user_login');
     $active_logins = array();
     $inactive_logins = array();
     $user_logins = array();
     $admin_logins = array();
     $sa_logins = array();
     foreach ($logins as $i) {
         if ($i['active']) {
             $active_logins[] = $i['id'];
         } else {
             $inactive_logins[] = $i['id'];
         }
         if ($i['admin'] == 0) {
             $user_logins[] = $i['id'];
         } elseif ($i['admin'] == 1) {
             $admin_logins[] = $i['id'];
         } else {
             $sa_logins[] = $i['id'];
         }
     }
     $this->rb->set_custom_filter('username', array('type' => 'select', 'label' => __('Active'), 'args' => array('__NULL__' => '---', 1 => __('Yes'), 2 => __('No')), 'trans' => array('__NULL__' => array(), 1 => array('login' => $active_logins), 2 => array('login' => $inactive_logins))));
     $this->rb->set_custom_filter('admin', array('type' => 'select', 'label' => __('Admin'), 'args' => array('__NULL__' => '---', 0 => __('No'), 1 => __('Administrator'), 2 => __('Super Administrator')), 'trans' => array('__NULL__' => array(), 0 => array('login' => $user_logins), 1 => array('login' => $admin_logins), 2 => array('login' => $sa_logins))));
     $this->rb->set_defaults(array('country' => Base_User_SettingsCommon::get('Base_RegionalSettings', 'default_country'), 'zone' => Base_User_SettingsCommon::get('Base_RegionalSettings', 'default_state'), 'permission' => Base_User_SettingsCommon::get('CRM_Common', 'default_record_permission'), 'home_country' => Base_User_SettingsCommon::get('Base_RegionalSettings', 'default_country'), 'home_zone' => Base_User_SettingsCommon::get('Base_RegionalSettings', 'default_state'), 'login' => 'new'));
     $this->rb->set_default_order(array('last_name' => 'ASC', 'first_name' => 'ASC'));
     $this->rb->set_additional_actions_method(array($this, 'user_actions'));
     $this->rb->set_additional_caption(__('Users'));
     $this->rb->disable_pdf();
     $this->rb->disable_export();
     $this->display_module($this->rb, array(array(), array('!login' => ''), array('work_phone' => false, 'admin' => true, 'mobile_phone' => false, 'city' => false, 'zone' => false, 'login' => true, 'access' => true, 'email' => true), array('username' => true, 'admin' => true, 'access' => true, 'related_companies' => false)));
     Base_ActionBarCommon::add('edit', __('E-mail header'), $this->create_callback_href(array('Base_BoxCommon', 'push_module'), array($this->get_type(), 'change_email_header')), __('Edit the header of the message that is sent to each newly created user'));
 }
Example #7
0
 public static function notification()
 {
     $time = time() - 24 * 3600;
     $arr = DB::GetAll('SELECT ul.login, ul.id as user_id, asm.id, asm.message, asm.posted_on, asm.to_user_login_id FROM apps_shoutbox_messages asm LEFT JOIN user_login ul ON ul.id=asm.base_user_login_id WHERE asm.posted_on>=%T AND asm.base_user_login_id!=%d AND (asm.to_user_login_id=%d OR asm.to_user_login_id is null) ORDER BY asm.posted_on DESC LIMIT 10', array($time, Base_AclCommon::get_user(), Base_AclCommon::get_user()));
     if (empty($arr)) {
         return array();
     }
     //print it out
     $ret = array();
     $tray = array();
     foreach ($arr as $row) {
         if (!$row['login']) {
             $row['login'] = '******';
         }
         $ret['shoutbox_' . $row['id']] = vsprintf('<font color="gray">[%s]</font><font color="blue">%s</font>: %s', array(Base_RegionalSettingsCommon::time2reg($row['posted_on']), $row['login'], $row['message']));
         $tray['shoutbox_' . $row['id']] = array('title' => __('Shoutbox Message'), 'body' => $row['to_user_login_id'] ? __('%s wrote to you: %s', array(Base_UserCommon::get_user_label($row['user_id'], true), $row['message'])) : __('%s wrote to all: %s', array(Base_UserCommon::get_user_label($row['user_id'], true), $row['message'])));
     }
     return array('notifications' => $ret, 'tray' => $tray);
 }
Example #8
0
	function toHtml() {
		$str = "";
		if ($this->_flagFrozen) {
			$str .= $this->getFrozenHtml();
		} else {
			$id = $this->getAttribute('id');
			$name = $this->getAttribute('name');
			if(!isset($id)) {
				$id = 'currency_field_'.$name;
				$this->updateAttributes(array('id'=>$id));
			}
			
			$this->dec_digits = DB::GetOne('SELECT MAX(decimals) FROM utils_currency');

			$str .= $this->_getTabs() . '<div style="position: relative;">';

			$str .= $this->_getTabs() .
					'<div style="margin-right:45px;" class="currency_amount"><input ' . $this->_getAttrString($this->_attributes) . ' '.
					Utils_TooltipCommon::open_tag_attrs(__('Example value: %s',array('123'.Utils_CurrencyFieldCommon::get_decimal_point().implode('',range(4,3+$this->dec_digits)))), false ).
					' /></div>';

			$str .= $this->_getTabs() .
					'<div style="margin-right:5px; width:40px; position:absolute;top:0px;right:0px;"><select style="width:40px;" name="__'.str_replace(array('[',']'),'',$name).'__currency" id="__'.$id.'__currency">';

			$curs = DB::GetAll('SELECT id, symbol, active FROM utils_currency ORDER BY code');
			foreach ($curs as $v) {
				if ($v['id']!=$this->currency && !$v['active']) continue;
				$str .= '<option value="'.$v['id'].'"';
				if ($v['id']==$this->currency) $str .= ' selected="1"';
				$str .= '>'.$v['symbol'].'</option>';
			}
			$str .= '</select></div>';

			$str .= $this->_getTabs() . '</div>';

			load_js('modules/Utils/CurrencyField/currency.js');
			$curr_format = '-?([0-9]*)\\'.Utils_CurrencyFieldCommon::get_decimal_point().'?[0-9]{0,'.$this->dec_digits.'}';
			eval_js('Event.observe(\''.$id.'\',\'keypress\',Utils_CurrencyField.validate.bindAsEventListener(Utils_CurrencyField,\''.Epesi::escapeJS($curr_format,false).'\'))');
			eval_js('Event.observe(\''.$id.'\',\'blur\',Utils_CurrencyField.validate_blur.bindAsEventListener(Utils_CurrencyField,\''.Epesi::escapeJS($curr_format,false).'\'))');
		}
		return $str;
	} //end func toHtml
Example #9
0
 public static function getOne($id)
 {
     $site = $_SESSION['site'];
     if (Funcs::$uri[0] == ONESSA_DIR) {
         $site = $_SESSION['OneSSA']['site'];
     }
     $sql = 'SELECT * FROM {{votes}} WHERE id=' . $id . ' AND site=' . $site . '';
     $data = DB::GetRow($sql);
     $sql = 'SELECT * FROM {{votes}} WHERE parent=' . $id . ' AND site=' . $site . ' ORDER BY num';
     $list = DB::GetAll($sql);
     $sum = 0;
     foreach ($list as $item) {
         $sum += $item['answers'];
     }
     foreach ($list as $i => $item) {
         if ($sum != 0) {
             $item['width'] = round($item['answers'] / $sum * 100);
         } else {
             $item['width'] = 0;
         }
         $data['list'][] = $item;
     }
     return $data;
 }
Example #10
0
 public function edit_permissions_rule($id = null, $clone = false)
 {
     if (Base_AdminCommon::get_access('Utils_RecordBrowser', 'permissions') != 2) {
         return false;
     }
     if ($this->is_back()) {
         return false;
     }
     load_js('modules/Utils/RecordBrowser/edit_permissions.js');
     $all_clearances = array('' => '---') + array_flip(Base_AclCommon::get_clearance(true));
     $all_fields = array();
     $this->init();
     foreach ($this->table_rows as $k => $v) {
         $all_fields[$v['id']] = $k;
     }
     $form = $this->init_module('Libs_QuickForm');
     $theme = $this->init_module('Base_Theme');
     $counts = array('clearance' => 5);
     $actions = $this->get_permission_actions();
     $form->addElement('select', 'action', __('Action'), $actions);
     $fields_permissions = $all_fields;
     for ($i = 0; $i < $counts['clearance']; $i++) {
         $form->addElement('select', 'clearance_' . $i, __('Clearance'), $all_clearances);
     }
     $defaults = array();
     foreach ($fields_permissions as $k => $v) {
         $defaults['field_' . $k] = 1;
         $form->addElement('checkbox', 'field_' . $k, _V($this->table_rows[$v]['name']));
     }
     $theme->assign('labels', array('and' => '<span class="joint">' . __('and') . '</span>', 'or' => '<span class="joint">' . __('or') . '</span>', 'caption' => $id ? __('Edit permission rule') : __('Add permission rule'), 'clearance' => __('Clearance requried'), 'fields' => __('Fields allowed'), 'crits' => __('Criteria required'), 'add_clearance' => __('Add clearance'), 'add_or' => __('Add criteria (or)'), 'add_and' => __('Add criteria (and)')));
     $current_clearance = 0;
     $crits = array();
     if ($id !== null && $this->tab != '__RECORDSETS__' && !preg_match('/,/', $this->tab)) {
         $row = DB::GetRow('SELECT * FROM ' . $this->tab . '_access AS acs WHERE id=%d', array($id));
         $defaults['action'] = $row['action'];
         $crits = Utils_RecordBrowserCommon::unserialize_crits($row['crits']);
         if (is_array($crits)) {
             $crits = Utils_RecordBrowser_Crits::from_array($crits);
         }
         $i = 0;
         $tmp = DB::GetAll('SELECT * FROM ' . $this->tab . '_access_clearance AS acs WHERE rule_id=%d', array($id));
         foreach ($tmp as $t) {
             $defaults['clearance_' . $i] = $t['clearance'];
             $i++;
         }
         $current_clearance += $i - 1;
         $tmp = DB::GetAll('SELECT * FROM ' . $this->tab . '_access_fields AS acs WHERE rule_id=%d', array($id));
         foreach ($tmp as $t) {
             unset($defaults['field_' . $t['block_field']]);
         }
     }
     $qbi = new Utils_RecordBrowser_QueryBuilderIntegration($this->tab);
     $qb = $qbi->get_builder_module($this, $crits);
     $qb->add_to_form($form, 'qb_crits', __('Crits'), 'qb_crits_editor');
     $form->setDefaults($defaults);
     if ($form->validate()) {
         $vals = $form->exportValues();
         $action = $vals['action'];
         $clearance = array();
         for ($i = 0; $i < $counts['clearance']; $i++) {
             if ($vals['clearance_' . $i]) {
                 $clearance[] = $vals['clearance_' . $i];
             }
         }
         $crits = $qbi->json_to_crits($vals['qb_crits']);
         $blocked_fields = array();
         foreach ($fields_permissions as $k => $v) {
             if (isset($vals['field_' . $k])) {
                 continue;
             }
             $blocked_fields[] = $k;
         }
         if ($id === null || $clone) {
             Utils_RecordBrowserCommon::add_access($this->tab, $action, $clearance, $crits, $blocked_fields);
         } else {
             Utils_RecordBrowserCommon::update_access($this->tab, $id, $action, $clearance, $crits, $blocked_fields);
         }
         return false;
     }
     eval_js('utils_recordbrowser__init_clearance(' . $current_clearance . ', ' . $counts['clearance'] . ')');
     eval_js('utils_recordbrowser__crits_initialized = true;');
     $form->assign_theme('form', $theme);
     $theme->assign('fields', $fields_permissions);
     $theme->assign('counts', $counts);
     $theme->display('edit_permissions');
     Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href());
     Base_ActionBarCommon::add('delete', __('Cancel'), $this->create_back_href());
     return true;
 }
Example #11
0
function show_trash($uid, $silence = false)
{
    $output = '<table><thead><tr> <th class="minimal">Headline</th> <th>Body</th> <th class="minimal">Time since deletion â–¼</th> </tr></thead> <tbody>';
    $trash = DB::GetAll('SELECT headline, body, time FROM {P}Trash WHERE uid = ' . DB::Q($uid) . ' ORDER BY time DESC');
    $table = new TablePrinter('tblTrash');
    $columns = array('Headline', 'Body', 'Time since deletion â–¼');
    $table->DefineColumns($columns, 'Body');
    foreach ($trash as $row) {
        if (empty($row['headline'])) {
            $row['headline'] = '<span class="unimportant">(Reply.)</span>';
        } else {
            $row['headline'] = htmlspecialchars($row['headline']);
        }
        $values = array($row['headline'], nl2br(htmlspecialchars($row['body'])), '<span class="help" title="' . format_date($row['time']) . '">' . calculate_age($row['time']) . '</span>');
        $table->Row($values);
    }
    if ($table->num_rows_fetched === 0) {
        return false;
    }
    return $table;
}
Example #12
0
	public static function tray_notification() {
		$methods = DB::GetAssoc('SELECT id,callback FROM utils_watchdog_category');
		foreach ($methods as $k=>$v) { 
			$methods[$k] = explode('::',$v);
		}
		$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,last_seen_event FROM utils_watchdog_subscription AS uws WHERE user_id=%d '.$only_new, array(Acl::get_user()));
		$ret = array();
		$tray = array();
		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;
			$ret['watchdog_'.$v['internal_id'].'_'.$v['category_id'].'_'.$v['last_seen_event']] = '<b>'.__('Watchdog - %s', array($data['category'])).':</b> '.$data['title'];
			
			$tray['watchdog_'.$v['internal_id'].'_'.$v['category_id'].'_'.$v['last_seen_event']] = array('title'=>__('Watchdog - %s', array($data['category'])), 'body'=>$data['title']);			
			
			if (isset($data['events']) && $data['events']) {
				$ret['watchdog_'.$v['internal_id'].'_'.$v['category_id'].'_'.$v['last_seen_event']] .= '<br><font size=-5 color=gray>'.$data['events'].'</font>';
			}
		}
		return array('notifications'=>$ret, 'tray'=>$tray);
	}
 /**
  * @static
  */
 function FindAllByCmd($classname, $cmd)
 {
     $arr = DB::GetAll($cmd);
     $result = array();
     foreach ($arr as $row) {
         eval('$obj = new ' . $classname . '();');
         foreach ($obj->_db_fields as $prop => $dummy) {
             $obj->{$prop} = $row[$prop];
         }
         $obj->_db_ProcessAfterFilter();
         $result[] = $obj;
     }
     return $result;
 }
Example #14
0
	public function edit_permissions_rule($id = null, $clone = false) {
		if (Base_AdminCommon::get_access('Utils_RecordBrowser', 'permissions')!=2) return false;
        if ($this->is_back()) {
            return false;
		}
		load_js('modules/Utils/RecordBrowser/edit_permissions.js');
		$all_clearances = array(''=>'---')+array_flip(Base_AclCommon::get_clearance(true));
		$all_fields = array();
		$this->init();
		foreach ($this->table_rows as $k=>$v)
			$all_fields[$v['id']] = $k;
		$js = '';
		$operators = array(
			'='=>__('equal'), 
			'!'=>__('not equal'), 
			'>'=>'>',
			'>='=>'>=',
			'<'=>'<',
			'<='=>'<='
		);

		$form = $this->init_module('Libs_QuickForm');
		$theme = $this->init_module('Base_Theme');
		
		$counts = array(
			'clearance'=>5,
			'ands'=>5,
			'ors'=>10
		);
		
		$actions = $this->get_permission_actions();
		$form->addElement('select', 'action', __('Action'), $actions);
		
		$fields_permissions = $all_fields;

		foreach ($all_fields as $k=>$v) {
			if ($this->table_rows[$v]['type']=='calculated' || $this->table_rows[$v]['type']=='hidden') unset($all_fields[$k]);
			else $this->manage_permissions_set_field_values($k);
		}

		$all_fields = array(
			':Created_by'=>__('Created by'),
			':Created_on'=>__('Created on'),
			':Edited_on'=>__('Edited on')
		) + $all_fields;
		if ($this->tab=='contact' || $this->tab=='company')
			$all_fields = array('id'=>__('ID')) + $all_fields;
		
		$this->manage_permissions_set_field_values(':Created_by', array('USER_ID'=>__('User Login')));
		$this->manage_permissions_set_field_values(':Created_on', Utils_RecordBrowserCommon::$date_values);
		$this->manage_permissions_set_field_values(':Edited_on', Utils_RecordBrowserCommon::$date_values);
		if ($this->tab=='contact')
			$this->manage_permissions_set_field_values('id', array('USER'=>__('User Contact')));
		if ($this->tab=='company')
			$this->manage_permissions_set_field_values('id', array('USER_COMPANY'=>__('User Company')));
		
		for ($i=0; $i<$counts['clearance']; $i++)
			$form->addElement('select', 'clearance_'.$i, __('Clearance'), $all_clearances);
		$current_or = array();
		$current_and = 0;
		
		foreach ($all_fields as $k=>$v) {
			if (isset($this->table_rows[$v])) {
				$v = $this->table_rows[$v]['name'];
			}
			$all_fields[$k] = _V($v);
		}
		
		for ($i=0; $i<$counts['ands']; $i++) {
			$current_or[$i] = 0;
			for ($j=0; $j<$counts['ors']; $j++) {
				$form->addElement('select', 'crits_'.$i.'_'.$j.'_field', __('Crits'), array(''=>'---')+$all_fields, array('onchange'=>'utils_recordbrowser__update_field_values('.$i.', '.$j.');', 'id'=>'crits_'.$i.'_'.$j.'_field'));
				$form->addElement('select', 'crits_'.$i.'_'.$j.'_op', __('Operator'), array(''=>'---')+$operators);
				$form->addElement('select', 'crits_'.$i.'_'.$j.'_value', __('Value'), array(), array('id'=>'crits_'.$i.'_'.$j.'_value', 'onchange'=>'utils_recordbrowser__update_field_sub_values('.$i.', '.$j.');'));
				$form->addElement('select', 'crits_'.$i.'_'.$j.'_sub_value', __('Subrecord Value'), array(), array('id'=>'crits_'.$i.'_'.$j.'_sub_value', 'style'=>'display:none;'));
				$js .= 'utils_recordbrowser__update_field_values('.$i.', '.$j.');';
			}
		}
		$defaults = array();
		foreach ($fields_permissions as $k=>$v) {
			$defaults['field_'.$k] = 1;
			$form->addElement('checkbox', 'field_'.$k, _V($this->table_rows[$v]['name']));
		}
		$theme->assign('labels', array(
			'and' => '<span class="joint">'.__('and').'</span>',
			'or' => '<span class="joint">'.__('or').'</span>',
			'caption' => $id?__('Edit permission rule'):__('Add permission rule'),
			'clearance' => __('Clearance requried'),
			'fields' => __('Fields allowed'),
			'crits' => __('Criteria required'),
			'add_clearance' => __('Add clearance'),
			'add_or' => __('Add criteria (or)'),
			'add_and' => __('Add criteria (and)')
 		));
		$current_clearance = 0;
		$sub_values = array();
		if ($id!==null && $this->tab!='__RECORDSETS__' && !preg_match('/,/',$this->tab)) {
			$row = DB::GetRow('SELECT * FROM '.$this->tab.'_access AS acs WHERE id=%d', array($id));
			
			$defaults['action'] = $row['action'];
			$crits = unserialize($row['crits']);
			$i = 0;
			$j = 0;
			$or = false;
			$first = true;
			foreach ($crits as $k=>$v) {
				$operator = '=';
				while (($k[0]<'a' || $k[0]>'z') && ($k[0]<'A' || $k[0]>'Z') && $k[0]!=':') {
					if ($k[0]=='!') $operator = '!';
					if ($k[0]=='(' && $or) $or = false;
					if ($k[0]=='|') $or = true;
					if ($k[0]=='<') $operator = '<';
					if ($k[0]=='>') $operator = '>';
					if ($k[0]=='~') $operator = DB::like();
					if ($k[1]=='=' && $operator!=DB::like()) {
						$operator .= '=';
						$k = substr($k, 2);
					} else $k = substr($k, 1);
				}
				if (!$first) {
					if ($or) $j++;
					else {
						$current_or[$i] += $j;
						$j = 0;
						$i++;
					}
				} else {
					$first = false;
				}
				$sub_value = null;
				if (!isset($r[$k]) && $k[strlen($k)-1]==']') {
					$sub_value = $v;
					list($k, $v) = explode('[', trim($k, ']'));
				}
				$defaults['crits_'.$i.'_'.$j.'_field'] = $k;
				$defaults['crits_'.$i.'_'.$j.'_op'] = $operator;
				$js .= '$("crits_'.$i.'_'.$j.'_value").value = "'.$v.'";';
				if ($sub_value!==null) $sub_values['crits_'.$i.'_'.$j.'_sub_value'] = $sub_value;
			}
			$current_or[$i] += $j;
			$current_and += $i;
			
			$i = 0;
			$tmp = DB::GetAll('SELECT * FROM '.$this->tab.'_access_clearance AS acs WHERE rule_id=%d', array($id));
			foreach ($tmp as $t) {
				$defaults['clearance_'.$i] = $t['clearance'];
				$i++;
			}
			$current_clearance += $i-1;
			
			$tmp = DB::GetAll('SELECT * FROM '.$this->tab.'_access_fields AS acs WHERE rule_id=%d', array($id));
			foreach ($tmp as $t) {
				unset($defaults['field_'.$t['block_field']]);
			}
		}
		for ($i=0; $i<$counts['ands']; $i++)
			for ($j=0; $j<$counts['ors']; $j++)
				$js .= 'utils_recordbrowser__update_field_sub_values('.$i.', '.$j.');';
		foreach ($sub_values as $k=>$v)
			$js .= '$("'.$k.'").value = "'.$v.'";';

		$form->setDefaults($defaults);
		
		if ($form->validate()) {
			$vals = $form->exportValues();
			$action = $vals['action'];

			$clearance = array();
			for ($i=0; $i<$counts['clearance']; $i++)
				if ($vals['clearance_'.$i]) $clearance[] = $vals['clearance_'.$i];
			
			$crits = array();
			for ($i=0; $i<$counts['ands']; $i++) {
				$or = '(';
				for ($j=0; $j<$counts['ors']; $j++) {
					if ($vals['crits_'.$i.'_'.$j.'_field'] && $vals['crits_'.$i.'_'.$j.'_op']) {
						if (!isset($operators[$vals['crits_'.$i.'_'.$j.'_op']])) trigger_error('Fatal error',E_USER_ERROR);
						if (!isset($all_fields[$vals['crits_'.$i.'_'.$j.'_field']])) trigger_error('Fatal error',E_USER_ERROR);
						$op = $vals['crits_'.$i.'_'.$j.'_op'];
						if ($op=='=') $op = '';
						if (isset($vals['crits_'.$i.'_'.$j.'_sub_value'])) {
							$vals['crits_'.$i.'_'.$j.'_field'] = $vals['crits_'.$i.'_'.$j.'_field'].'['.$vals['crits_'.$i.'_'.$j.'_value'].']';
							$vals['crits_'.$i.'_'.$j.'_value'] = $vals['crits_'.$i.'_'.$j.'_sub_value'];
						}
						$next = array($or.$op.$vals['crits_'.$i.'_'.$j.'_field'] => $vals['crits_'.$i.'_'.$j.'_value']);
						$crits = Utils_RecordBrowserCommon::merge_crits($crits, $next);
					}
					$or = '|';
				}
			}

			$blocked_fields = array();
			foreach ($fields_permissions as $k=>$v) {
				if (isset($vals['field_'.$k])) continue;
				$blocked_fields[] = $k;
			}
			
			if ($id===null || $clone)
				Utils_RecordBrowserCommon::add_access($this->tab, $action, $clearance, $crits, $blocked_fields);
			else
				Utils_RecordBrowserCommon::update_access($this->tab, $id, $action, $clearance, $crits, $blocked_fields);
			return false;
		}
		
		eval_js($js);

		eval_js('utils_recordbrowser__init_clearance('.$current_clearance.', '.$counts['clearance'].')');
		eval_js('utils_recordbrowser__init_crits_and('.$current_and.', '.$counts['ands'].')');
		for ($i=0; $i<$counts['ands']; $i++)
				eval_js('utils_recordbrowser__init_crits_or('.$i.', '.$current_or[$i].', '.$counts['ors'].')');
		eval_js('utils_recordbrowser__crits_initialized = true;');
		
		$form->assign_theme('form', $theme);
		$theme->assign('fields', $fields_permissions);
		$theme->assign('counts', $counts);
		
		$theme->display('edit_permissions');
		Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href());
		Base_ActionBarCommon::add('delete', __('Cancel'), $this->create_back_href());
		return true;
	}
Example #15
0
 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);
         }
     }
 }
 function GetAll()
 {
     return DB::GetAll($this);
 }
Example #17
0
	public function body() {
		$gb = $this->init_module('Utils/GenericBrowser',null,'messages');
		$gb->set_table_columns(array(
			array('name'=>__('Alert on'), 'width'=>20),
			array('name'=>__('Message'), 'width'=>50),
			array('name'=>__('Users'), 'width'=>30)
				));
		$data = DB::GetAll('SELECT * FROM utils_messenger_message WHERE page_id=\''.$this->mid.'\'');
		foreach($data as & $row) {
			$row['users'] = DB::GetCol('SELECT user_login_id FROM utils_messenger_users WHERE message_id=\''.$row['id'].'\'');
			$r = & $gb->get_new_row();
			if(is_array($this->users)) {
				$us = '';
				foreach($row['users'] as $rr)
					if(isset($this->users[$rr])) 
						$us .= $this->users[$rr].'<br>';
			} else
				$us = Base_UserCommon::get_user_login($this->users);
				
			$r->add_data(Base_RegionalSettingsCommon::time2reg($row['alert_on']),$row['message'],$us);
			$r->add_action($this->create_callback_href(array($this,'push_box0'),array('edit',array($row),array($this->real_id,$this->callback_method,$this->callback_args,$this->def_date,$this->users))),'Edit');
			$r->add_action($this->create_confirm_callback_href(__('Are you sure?'),array($this,'delete_entry'),$row['id']),'Delete');
		}
		$this->display_module($gb);
		
		Base_ActionBarCommon::add('add',__('New alert'),$this->create_callback_href(array($this,'push_box0'),array('edit',array(false),array($this->real_id,$this->callback_method,$this->callback_args,$this->def_date,$this->users))));	
	}
Example #18
0
    public static function cron2() {
        $interval = DB::is_postgresql() ? DB::qstr('4 minute') : '4 minute';
		$arr = DB::GetAll('SELECT m.*,u.* FROM utils_messenger_message m INNER JOIN utils_messenger_users u ON u.message_id=m.id WHERE u.follow=0 AND m.alert_on+INTERVAL ' . $interval . ' <%T',array(time()));
		foreach($arr as $row) {
			Acl::set_user($row['user_login_id']);
			$always_follow = Base_User_SettingsCommon::get('Utils_Messenger','always_follow_me');
			if(!$always_follow && $row['done']) continue;
			ob_start();
			$fret = call_user_func_array(unserialize($row['callback_method']),unserialize($row['callback_args']));
			ob_end_clean();
			DB::Execute('UPDATE utils_messenger_users SET follow=1 WHERE message_id=%d AND user_login_id=%d',array($row['id'],$row['user_login_id']));

			$mail = Base_User_SettingsCommon::get('Utils_Messenger','mail');
			if($mail) {
				$msg = __('Alert on: %s',array(Base_RegionalSettingsCommon::time2reg($row['alert_on'],2)))."\n".$fret."\n".($row['message']?__('Alarm comment: %s',array($row['message'])):'');
				Base_MailCommon::send($mail,'Alert!',$msg);
			}
			Acl::set_user();
		}
		
		return '';
	}
Example #19
0
        $links = 0;
    }
    if ($old_checkpoint->has('links_qty')) {
        $links_qty = $old_checkpoint->get('links_qty');
    } else {
        $links_qty = DB::GetOne('SELECT count(*) FROM utils_attachment_link');
        $old_checkpoint->set('links_qty', $links_qty);
    }
    while ($ret = DB::SelectLimit('SELECT * FROM utils_attachment_link ORDER BY id', 1, $links++)) {
        $link = $ret->FetchRow();
        if (!$link) {
            break;
        }
        Patch::set_message('Processing note: ' . $links . '/' . $links_qty);
        $old_checkpoint->require_time(2);
        $notes = DB::GetAll('SELECT * FROM utils_attachment_note WHERE attach_id=%d ORDER BY revision', $link['id']);
        $note = array_shift($notes);
        Acl::set_user($note['created_by']);
        $rid = Utils_RecordBrowserCommon::new_record('utils_attachment', array('title' => $link['title'], 'note' => $note['text'], 'permission' => $link['permission'], 'sticky' => $link['sticky'], 'crypted' => array('crypted' => $link['crypted']), 'func' => $link['func'], 'args' => $link['args'], '__date' => $note['created_on'], 'local' => $link['local']));
        //    DB::Execute('INSERT INTO utils_attachment_local(local,attachment) VALUES(%s,%d)',array($link['local'],$rid));
        $map[$link['id']] = $rid;
        foreach ($notes as $note) {
            Acl::set_user($note['created_by']);
            Utils_RecordBrowserCommon::update_record('utils_attachment', $rid, array('note' => $note['text'], '__date' => $note['created_on']));
        }
        Acl::set_user($us);
        $old_checkpoint->set('links', $links);
        $old_checkpoint->set('map', $map);
    }
}
$old_checkpoint->done();
Example #20
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);
 }
Example #21
0
 public static function db_GetAll($query)
 {
     $DB = new DB(self::$config['HOST'], self::$config['USER'], self::$config['PASSWORD'], self::$config['DATABASE']);
     $result = $DB->GetAll($query);
     return $result;
 }
Example #22
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);
 }
Example #23
0
 * @license MIT
 * @version 1.0
 * @package epesi-apps
 * @subpackage shoutbox
 */
ob_start();
define('CID', false);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Base_AclCommon::is_user()) {
    exit;
}
$myid = Base_AclCommon::get_user();
$uid = isset($_GET['uid']) && is_numeric($_GET['uid']) ? $_GET['uid'] : null;
//get last 20 messages
$arr = DB::GetAll('SELECT asm.base_user_login_id as from_login_id, asm.to_user_login_id as to_login_id,asm.message, asm.posted_on FROM apps_shoutbox_messages asm WHERE ' . ($uid ? '(base_user_login_id=' . $myid . ' AND to_user_login_id=' . $uid . ') OR (base_user_login_id=' . $uid . ' AND to_user_login_id=' . $myid . ')' : 'to_user_login_id is null OR to_user_login_id=' . $myid . ' OR base_user_login_id=' . $myid) . ' ORDER BY asm.posted_on DESC LIMIT 20');
//print it out
foreach ($arr as $row) {
    $daydiff = floor((time() - strtotime($row['posted_on'])) / 86400);
    switch (true) {
        case $daydiff < 1:
            $fcolor = '#000000';
            break;
        case $daydiff < 3:
            $fcolor = '#444444';
            break;
        case $daydiff < 7:
            $fcolor = '#888888';
            break;
        default:
            $fcolor = '#AAAAAA';
Example #24
0
 public static function check_table_name($tab, $flush = false, $failure_on_missing = true)
 {
     static $tables = null;
     if ($tab == '__RECORDSETS__' || preg_match('/,/', $tab)) {
         return true;
     }
     if ($tables === null || $flush) {
         $r = DB::GetAll('SELECT tab FROM recordbrowser_table_properties');
         $tables = array();
         foreach ($r as $v) {
             $tables[$v['tab']] = true;
         }
     }
     if (!isset($tables[$tab]) && !$flush && $failure_on_missing) {
         trigger_error('RecordBrowser critical failure, terminating. (Requested ' . serialize($tab) . ', available ' . print_r($tables, true) . ')', E_USER_ERROR);
     }
     return isset($tables[$tab]);
 }
Example #25
0
 public static function set_default_applets()
 {
     $tabs = DB::GetAll('SELECT id,pos,name FROM base_dashboard_default_tabs');
     foreach ($tabs as $tab) {
         DB::Execute('INSERT INTO base_dashboard_tabs(user_login_id,pos,name) VALUES(%d,%d,%s)', array(Base_AclCommon::get_user(), $tab['pos'], $tab['name']));
         $id = DB::Insert_ID('base_dashboard_tabs', 'id');
         $ret = DB::GetAll('SELECT id,module_name,col,color,tab FROM base_dashboard_default_applets WHERE tab=%d ORDER BY pos', array($tab['id']));
         foreach ($ret as $row) {
             DB::Execute('INSERT INTO base_dashboard_applets(module_name,col,user_login_id,color,tab) VALUES(%s,%d,%d,%d,%d)', array($row['module_name'], $row['col'], Base_AclCommon::get_user(), $row['color'], $id));
             $ins_id = DB::Insert_ID('base_dashboard_applets', 'id');
             $ret_set = DB::GetAll('SELECT name,value FROM base_dashboard_default_settings WHERE applet_id=%d', array($row['id']));
             foreach ($ret_set as $row_set) {
                 DB::Execute('INSERT INTO base_dashboard_settings(applet_id,value,name) VALUES(%d,%s,%s)', array($ins_id, $row_set['value'], $row_set['name']));
             }
         }
     }
 }
Example #26
0
 public static function get_all($start, $end)
 {
     return DB::GetAll('SELECT \'\' as additional_info,\'\' as additional_info2, color,start,duration,title,description,id,timeless FROM tests_calendar_event WHERE ((start>=%d AND start<%d))', array(strtotime($start), strtotime($end)));
 }
<?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'));
}
Example #28
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;
    }
Example #29
0
 public static function delete_applets($module)
 {
     $module = str_replace('/', '_', $module);
     $ret = DB::GetAll('SELECT id FROM base_dashboard_default_applets WHERE module_name=%s', array($module));
     foreach ($ret as $row) {
         DB::Execute('DELETE FROM base_dashboard_default_settings WHERE applet_id=%d', array($row['id']));
     }
     DB::Execute('DELETE FROM base_dashboard_default_applets WHERE module_name=%s', array($module));
     $ret = DB::GetAll('SELECT id FROM base_dashboard_applets WHERE module_name=%s', array($module));
     foreach ($ret as $row) {
         DB::Execute('DELETE FROM base_dashboard_settings WHERE applet_id=%d', array($row['id']));
     }
     DB::Execute('DELETE FROM base_dashboard_applets WHERE module_name=%s', array($module));
 }
Example #30
0
 * @version 1.0
 * @package epesi-Utils
 * @subpackage Messenger
 */
header("Content-type: text/javascript");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// date in the past
define('READ_ONLY_SESSION', true);
define('CID', false);
define('JS_OUTPUT', 1);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Acl::is_user()) {
    return;
}
$arr = DB::GetAll('SELECT m.* FROM utils_messenger_message m INNER JOIN utils_messenger_users u ON u.message_id=m.id WHERE u.user_login_id=%d AND u.done=0 AND m.alert_on<%T', array(Acl::get_user(), time()));
//print it out
print 'utils_messenger_on=false;';
$t = time();
foreach ($arr as $row) {
    if (isset($_SESSION['utils_messenger_holdon'][$row['id']]) && $_SESSION['utils_messenger_holdon'][$row['id']] > $t) {
        continue;
    }
    ob_start();
    $ret = call_user_func_array(unserialize($row['callback_method']), unserialize($row['callback_args']));
    ob_clean();
    print 'if(confirm(\'' . Epesi::escapeJS(__('Alert on: %s', array(Base_RegionalSettingsCommon::time2reg($row['alert_on']))) . "\n" . $ret . "\n" . ($row['message'] ? __('Alarm comment: %s', array($row['message'])) : '') . "\n\n" . __('Are you sure you want to turn off the alarm?'), false) . '\')) new Ajax.Request(\'modules/Utils/Messenger/turnoff.php\',{method:\'get\',parameters:{id:' . $row['id'] . '}});';
}
print 'utils_messenger_on=true;';
exit;