Example #1
0
 function is_user_in_group($uid, $group)
 {
     // $groups_arr = Acl::$gacl->get_object_groups($uid);
     $object_id = $uid;
     $object_type = 'aro';
     $group_table = 'aro_groups';
     $map_table = 'groups_aro_map';
     $query = 'SELECT gm.group_id FROM ' . $map_table . ' gm ';
     $query .= 'WHERE gm.' . $object_type . '_id=' . $object_id;
     $rs = DB::Execute($query);
     $groups_arr = array();
     while ($row = $rs->FetchRow()) {
         $groups_arr[] = $row[0];
     }
     // END
     if (!$groups_arr) {
         return false;
     }
     $groups = array();
     foreach ($groups_arr as $id) {
         //$arr = Acl::$gacl->get_group_data($id);
         $group_id = $id;
         $group_type = 'aro';
         $table = 'aro_groups';
         $query = 'SELECT id, parent_id, value, name, lft, rgt FROM ' . $table . ' WHERE id=' . $group_id;
         $arr = DB::GetRow($query);
         // END
         if ($arr[3] == $group) {
             return true;
         }
     }
     return false;
 }
Example #2
0
 function DispatchPollUpdateContact(PollUpdateContactResponse $resp)
 {
     if ($resp->IsFailed()) {
         Log::Log(sprintf('DispatchPollUpdateContact failed. Registry response: %s', $resp->ErrMsg), E_USER_ERROR);
         throw new Exception($resp->ErrMsg, $resp->Code);
     }
     if ($resp->Succeed()) {
         $Contact = $this->DBContact->LoadByCLID($resp->CLID);
         try {
             // Get remote updated contact
             $Contact = $this->GetRemoteContact($Contact);
         } catch (NotImplementedException $e) {
             // Get updates from local history
             $op = $this->DB->GetRow('SELECT * FROM pending_operations WHERE objectid=? AND objecttype=?', array($Contact->ID, self::OBJ_CONTACT));
             if (!$op) {
                 throw new Exception('Pending operation not found');
             }
             $After = unserialize($op['object_after']);
             $fields = array();
             foreach ($Contact->GetEditableNames() as $n) {
                 $fields[$n] = $After->GetField($n);
             }
             $Contact->SetFieldList($fields);
         }
         $this->DBContact->Save($Contact);
         $this->FireEvent('ContactUpdated', $Contact);
     }
 }
Example #3
0
 public static function send_translation($lang, $org, $trans)
 {
     if (!self::allow_sending()) {
         return false;
     }
     $ip = gethostbyname($_SERVER['SERVER_NAME']);
     $r = DB::GetRow('SELECT * FROM base_lang_trans_contrib WHERE user_id=%d', array(Acl::get_user()));
     $q = array('first_name' => $r['first_name'], 'last_name' => $r['last_name'], 'lang' => $lang, 'ip' => $ip, 'original' => $org, 'translation' => $trans, 'credits' => $r['credits'], 'credits_website' => $r['credits_website'], 'contact_email' => $r['contact_email']);
     $ret = file_get_contents(self::translation_server_url . '/translations.php?' . http_build_query($q));
     $success = 'OK;' == $ret;
     return $success;
 }
 function FindByCmd($cmd)
 {
     $this->_db_Init();
     $row = DB::GetRow($cmd);
     if ($row === null) {
         return false;
     }
     foreach ($this->_db_fields as $prop => $dummy) {
         $this->{$prop} = $row[$prop];
     }
     $this->_db_ProcessAfterFilter();
     return true;
 }
Example #5
0
 public static function get_admin_level($user = null)
 {
     if ($user === null) {
         $user = self::get_user();
     }
     $admin = @DB::GetRow('SELECT * FROM user_login WHERE id=%d', array($user));
     if ($admin && !empty($admin) && !isset($admin['admin'])) {
         return 2;
     } else {
         $admin = isset($admin['admin']) ? $admin['admin'] : 0;
     }
     return $admin;
 }
Example #6
0
 public function edit_currency($id)
 {
     if ($this->is_back()) {
         return false;
     }
     $form = $this->init_module('Libs_QuickForm');
     $form->addElement('header', 'header', __('Edit currency'));
     $form->addElement('text', 'code', __('Code'));
     $form->addElement('text', 'symbol', __('Symbol'));
     $form->addElement('select', 'pos_before', __('Symbol position'), self::$positions);
     $form->addElement('text', 'decimal_sign', __('Decimal sign'));
     $form->addElement('text', 'thousand_sign', __('Thousand sign'));
     $form->addElement('text', 'decimals', __('Decimals'));
     $form->addElement('select', 'default_currency', __('Default'), self::$active);
     $form->addElement('select', 'active', __('Active'), self::$active);
     $form->addRule('code', __('Code must be up to 16 characters long'), 'maxlength', 16);
     $form->addRule('symbol', __('Symbol must be up to 8 characters long'), 'maxlength', 8);
     $form->addRule('decimal_sign', __('Decimal sign must be up to 2 characters long'), 'maxlength', 2);
     $form->addRule('thousand_sign', __('Thousand sign must be up to 2 characters long'), 'maxlength', 2);
     $form->addRule('decimals', __('Field must hold numeric value'), 'numeric');
     $form->addRule('code', __('Field required'), 'required');
     $form->addRule('symbol', __('Field required'), 'required');
     $form->addRule('decimal_sign', __('Field required'), 'required');
     $form->addRule('decimals', __('Field required'), 'required');
     if ($id !== null) {
         $defs = DB::GetRow('SELECT * FROM utils_currency WHERE id=%d', array($id));
         $form->setDefaults($defs);
         if ($defs['default_currency']) {
             $form->freeze(array('default_currency'));
         }
     }
     if ($form->validate()) {
         $vals = $form->exportValues();
         if (isset($vals['default_currency']) && $vals['default_currency']) {
             DB::Execute('UPDATE utils_currency SET default_currency=0');
         }
         $vals = array($vals['code'], $vals['symbol'], $vals['pos_before'], $vals['decimal_sign'], $vals['thousand_sign'], $vals['decimals'], $vals['active'], isset($vals['default_currency']) ? $vals['default_currency'] : 1);
         if ($id !== null) {
             $vals[] = $id;
             $sql = 'UPDATE utils_currency SET ' . 'code=%s, ' . 'symbol=%s, ' . 'pos_before=%d, ' . 'decimal_sign=%s, ' . 'thousand_sign=%s, ' . 'decimals=%d, ' . 'active=%d,' . 'default_currency=%d' . ' WHERE id=%d';
         } else {
             $sql = 'INSERT INTO utils_currency (' . 'code, ' . 'symbol, ' . 'pos_before, ' . 'decimal_sign, ' . 'thousand_sign, ' . 'decimals, ' . 'active, ' . 'default_currency' . ') VALUES (' . '%s, ' . '%s, ' . '%d, ' . '%s, ' . '%s, ' . '%d, ' . '%d, ' . '%d' . ')';
         }
         DB::Execute($sql, $vals);
         return false;
     }
     $form->display();
     Base_ActionBarCommon::add('back', __('Back'), $this->create_back_href());
     Base_ActionBarCommon::add('save', __('Save'), $form->get_submit_form_href());
     return true;
 }
Example #7
0
 public static function meta($id, $use_cache = true)
 {
     static $meta_cache = array();
     if (!is_numeric($id)) {
         $id = self::get_storage_id_by_link($id);
     }
     if ($use_cache && isset($meta_cache[$id])) {
         return $meta_cache[$id];
     }
     $meta = DB::GetRow('SELECT * FROM utils_filestorage_files WHERE id=%d', array($id));
     if (!$meta) {
         throw new Utils_FileStorage_StorageNotFound('Exception - DB storage object not found: ' . $id);
     }
     $meta['file'] = self::get_storage_file_path($meta['hash']);
     if (!file_exists($meta['file'])) {
         throw new Utils_FileStorage_FileNotFound('Exception - file not found: ' . $meta['file']);
     }
     $meta['links'] = DB::GetCol('SELECT link FROM utils_filestorage_link WHERE storage_id=%d', array($id));
     $meta_cache[$id] = $meta;
     return $meta;
 }
Example #8
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 #9
0
    if (!isset($E_SESSION['user'])) {
        throw new Exception('Not logged');
    }
    if (isset($_GET['_autologin_id'])) {
        $id = $_GET['_autologin_id'];
        setcookie('rc_account', $id);
    } elseif (isset($_COOKIE['rc_account'])) {
        $id = $_COOKIE['rc_account'];
    } else {
        throw new Exception('Forbidden');
    }
    if (!is_numeric($id)) {
        throw new Exception('Invalid account id');
    }
    global $account;
    $account = DB::GetRow('SELECT * FROM rc_accounts_data_1 WHERE id=%d AND active=1', array($id));
    if ($E_SESSION['user'] !== $account['f_epesi_user']) {
        throw new Exception('Access Denied');
    }
} catch (Exception $ex) {
    header("Cache-Control: private, no-cache, no-store, must-revalidate, post-check=0, pre-check=0");
    header("Pragma: no-cache");
    header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    die($ex->getMessage());
}
/*
 +-----------------------------------------------------------------------+
 | Local configuration for the Roundcube Webmail installation.           |
 |                                                                       |
 | This is a sample configuration file only containing the minumum       |
<?php

defined("_VALID_ACCESS") || die('Direct access forbidden');
$mysql = DB::is_mysql();
if ($mysql) {
    // remove foregin keys
    foreach (array('history', 'session_client') as $tab) {
        $a = DB::GetRow("SHOW CREATE TABLE {$tab}");
        if (preg_match('/CONSTRAINT (.+) FOREIGN KEY .*session_name/', $a[1], $m)) {
            DB::Execute("ALTER TABLE {$tab} DROP FOREIGN KEY " . $m[1]);
        }
    }
}
PatchUtil::db_alter_column('session', 'name', 'C(128) NOTNULL');
PatchUtil::db_alter_column('session_client', 'session_name', 'C(128) NOTNULL');
PatchUtil::db_alter_column('history', 'session_name', 'C(128) NOTNULL');
if ($mysql) {
    DB::Execute('ALTER TABLE history ADD FOREIGN KEY (session_name) REFERENCES session(name)');
    DB::Execute('ALTER TABLE session_client ADD FOREIGN KEY (session_name) REFERENCES session(name)');
}
 function GetRow()
 {
     return DB::GetRow($this);
 }
Example #12
0
 public static function change_node_position($id, $new_pos)
 {
     DB::StartTrans();
     $node = DB::GetRow('SELECT * FROM utils_commondata_tree WHERE id=%d', array($id));
     if ($node) {
         // move all following nodes back
         DB::Execute('UPDATE utils_commondata_tree SET position=position-1 WHERE parent_id=%d AND position>%d', array($node['parent_id'], $node['position']));
         // make place for moved node
         DB::Execute('UPDATE utils_commondata_tree SET position=position+1 WHERE parent_id=%d AND position>=%d', array($node['parent_id'], $new_pos));
         // set new node position
         DB::Execute('UPDATE utils_commondata_tree SET position=%d WHERE id=%d', array($new_pos, $id));
     }
     DB::CompleteTrans();
 }
Example #13
0
 public function translations()
 {
     global $translations;
     global $custom_translations;
     load_js('modules/Base/Lang/Administrator/js/main.js');
     eval_js('translate_init();');
     $lp = $this->init_module('Utils/LeightboxPrompt');
     $form = $this->init_module('Libs/QuickForm', null, 'translations_sending');
     $desc = '<div id="trans_sett_info" style="line-height:17px;">';
     $desc .= __('You have now option to contribute with your translations to help us deliver EPESI in various languages. You can opt in to send your translations to EPESI central database, allowing to deliver EPESI in your language to other users.') . '<br>';
     $desc .= __('Please note that the translations you submit aren\'t subject to copyright. EPESI Team will distribute the translations free of charge to the end users.') . '<br>';
     $desc .= __('The only data being sent is the values of the fields presented below and the translated strings, we do not receive any other information contained in EPESI.') . '<br>';
     $desc .= __('You can also change your Translations Contribution settings at later time.') . '<br>';
     $desc .= '</div>';
     eval_js('$("trans_sett_info").up("td").setAttribute("colspan",2);');
     eval_js('$("trans_sett_info").up("td").style.borderRadius="0";');
     // Not really nice, but will have to do for now
     eval_js('$("decription_label").up("td").hide();');
     eval_js('function update_credits(){$("contact_email").disabled=$("credits_website").disabled=!$("include_credits").checked||!$("allow").checked;}');
     eval_js('update_credits();');
     $ip = gethostbyname($_SERVER['SERVER_NAME']);
     $me = CRM_ContactsCommon::get_my_record();
     $form->addElement('static', 'header', '<div id="decription_label" />', $desc);
     $form->addElement('checkbox', 'allow', __('Enable sending translations'), null, array('id' => 'allow', 'onchange' => '$("include_credits").disabled=$("first_name").disabled=$("last_name").disabled=!this.checked;update_credits();'));
     $form->addElement('text', 'first_name', __('First Name'), array('id' => 'first_name'));
     $form->addElement('text', 'last_name', __('Last Name'), array('id' => 'last_name'));
     $form->addElement('checkbox', 'include_credits', __('Include in credits'), null, array('id' => 'include_credits', 'onchange' => 'update_credits();'));
     $form->addElement('text', 'credits_website', __('Credits website'), array('id' => 'credits_website'));
     $form->addElement('text', 'contact_email', __('Contact e-mail'), array('id' => 'contact_email'));
     $form->addElement('static', 'IP', __('IP'), $ip);
     $lp->add_option(null, null, null, $form);
     eval_js('$("first_name").disabled=$("last_name").disabled=!$("allow").checked;');
     $vals = $lp->export_values();
     if ($vals) {
         $values = $vals['form'];
         if (!isset($values['allow'])) {
             $values['allow'] = 0;
         }
         if (!isset($values['first_name'])) {
             $values['first_name'] = '';
         }
         if (!isset($values['last_name'])) {
             $values['last_name'] = '';
         }
         if (!isset($values['include_credits'])) {
             $values['include_credits'] = 0;
         }
         if (!isset($values['credits_website'])) {
             $values['credits_website'] = '';
         }
         if (!isset($values['contact_email'])) {
             $values['contact_email'] = '';
         }
         DB::Execute('DELETE FROM base_lang_trans_contrib WHERE user_id=%d', array(Acl::get_user()));
         DB::Execute('INSERT INTO base_lang_trans_contrib (user_id, allow, first_name, last_name, credits, credits_website, contact_email) VALUES (%d, %d, %s, %s, %d, %s, %s)', array(Acl::get_user(), $values['allow'], $values['first_name'], $values['last_name'], $values['include_credits'], $values['credits_website'], $values['contact_email']));
     }
     $allow_sending = Base_Lang_AdministratorCommon::allow_sending(true);
     if ($allow_sending === null || $allow_sending === false) {
         $form->setDefaults(array('allow' => 0, 'first_name' => $me['first_name'], 'last_name' => $me['last_name'], 'contact_email' => $me['email']));
     } else {
         $r = DB::GetRow('SELECT * FROM base_lang_trans_contrib WHERE user_id=%d', array(Acl::get_user()));
         if (!$r['first_name']) {
             $r['first_name'] = $me['first_name'];
         }
         if (!$r['last_name']) {
             $r['last_name'] = $me['last_name'];
         }
         if (!$r['contact_email']) {
             $r['contact_email'] = $me['email'];
         }
         $form->setDefaults(array('allow' => $r['allow'], 'first_name' => $r['first_name'], 'last_name' => $r['last_name'], 'contact_email' => $r['contact_email'], 'credits_website' => $r['credits_website'], 'include_credits' => $r['credits']));
     }
     Base_ActionBarCommon::add('settings', __('Translations Contributions'), $lp->get_href());
     $this->display_module($lp, array(__('Translations Contributions settings')));
     if (Base_AdminCommon::get_access('Base_Lang_Administrator', 'new_langpack')) {
         Base_ActionBarCommon::add('add', __('New langpack'), $this->create_callback_href(array($this, 'new_lang_pack')));
     }
     if (Base_AdminCommon::get_access('Base_Lang_Administrator', 'select_language')) {
         Base_ActionBarCommon::add('refresh', __('Refresh languages'), $this->create_callback_href(array('Base_LangCommon', 'refresh_cache')));
     }
     $form2 = $this->init_module('Libs/QuickForm', null, 'translaction_filter');
     $form2->addElement('select', 'lang_filter', __('Filter'), array(__('Show all'), __('Show with custom translation'), __('Show with translation'), __('Show without translation')), array('onchange' => $form2->get_submit_form_js()));
     if ($form2->validate()) {
         $vals = $form2->exportValues();
         $this->set_module_variable('filter', $vals['lang_filter']);
     }
     $filter = $this->get_module_variable('filter', 0);
     $form2->setDefaults(array('lang_filter' => $filter));
     ob_start();
     $form2->display_as_row();
     $trans_filter = ob_get_clean();
     if (!isset($_SESSION['client']['base_lang_administrator']['currently_translating'])) {
         $_SESSION['client']['base_lang_administrator']['currently_translating'] = Base_LangCommon::get_lang_code();
     }
     if (!isset($_SESSION['client']['base_lang_administrator']['notice'])) {
         print '<span class="important_notice">' . __('Please make sure the correct language is selected in the box below before you start translating') . ' <a style="float:right;" ' . $this->create_callback_href(array($this, 'hide_notice')) . '>' . __('Discard') . '</a>' . '</span>';
     }
     if (Base_AdminCommon::get_access('Base_Lang_Administrator', 'translate')) {
         $langs = Base_LangCommon::get_installed_langs();
         $form = $this->init_module('Libs/QuickForm', null, 'language_selected');
         $form->addElement('select', 'lang_code', __('Currently Translating'), $langs, array('onchange' => $form->get_submit_form_js()));
         $currently_translating = $_SESSION['client']['base_lang_administrator']['currently_translating'];
         $form->setDefaults(array('lang_code' => $currently_translating));
         if ($form->validate()) {
             $form->process(array($this, 'submit_language_select'));
         }
         if ($allow_sending) {
             $warning_mgs = __('All custom translations will be sent to our server right after you will input them. Use this mode only, if you wish to contribute your translations. If you are going to change meaning of any string, then please disable sending translations.');
             print "<h1 style=\"color:red; width: 70%\">{$warning_mgs}</h1>";
         } else {
             $contribution_mgs = __('If you wish to help us with translating EPESI to your language, then click Translation Contribution in the Action Bar.');
             print "<h3>{$contribution_mgs}</h3>";
         }
         $form->display_as_column();
         if ($allow_sending) {
             $href = $this->create_confirm_callback_href(__('Are you sure?'), array($this, 'send_lang_ajax'), array($currently_translating));
             print "<h4><a {$href}>" . __('Send all your custom translations for language %s', array($langs[$currently_translating])) . "</a></h4>";
         }
         $help_msg = __('You can open next string to translate with space button');
         print "<p>{$help_msg}</p>";
     }
     Base_LangCommon::load($_SESSION['client']['base_lang_administrator']['currently_translating']);
     $data = array();
     foreach ($custom_translations as $o => $t) {
         if ($t || !isset($translations[$o])) {
             $translations[$o] = $t;
         }
     }
     foreach ($translations as $o => $t) {
         if (isset($custom_translations[$o]) && $custom_translations[$o]) {
             $t = $custom_translations[$o];
         } else {
             if ($filter == 1) {
                 continue;
             }
         }
         if ($filter == 2 && !$t) {
             continue;
         }
         if ($filter == 3 && $t) {
             continue;
         }
         $span_id = 'trans__' . md5($o);
         if (Base_AdminCommon::get_access('Base_Lang_Administrator', 'translate')) {
             $org = '<a href="javascript:void(0);" onclick="lang_translate(\'' . Epesi::escapeJS(htmlspecialchars($o)) . '\',\'' . $span_id . '\');">' . $o . '</a>';
             $t = '<span id="' . $span_id . '">' . $t . '</span>';
         }
         eval_js('translate_add_id("' . $span_id . '","' . Epesi::escapeJS($o) . '");');
         $data[] = array($org, $t);
     }
     $gb = $this->init_module('Utils/GenericBrowser', null, 'lang_translations');
     $gb->set_custom_label($trans_filter);
     $gb->set_table_columns(array(array('name' => __('Original'), 'order_preg' => '/^<[^>]+>([^<]*)<[^>]+>$/i', 'search' => 'original'), array('name' => __('Translated'), 'search' => 'translated')));
     //$limit = $gb->get_limit(count($data));
     $id = 0;
     foreach ($data as $v) {
         //if ($id>=$limit['offset'] && $id<$limit['offset']+$limit['numrows'])
         $gb->add_row_array($v);
         $id++;
     }
     Base_LangCommon::load();
     $this->display_module($gb, array(true), 'automatic_display');
     Utils_ShortcutCommon::add(array(' '), 'translate_first_on_the_list', array('disable_in_input' => 1));
 }
Example #14
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;
 }
Example #15
0
 * @subpackage attachment
 */
if (!isset($_REQUEST['cid']) || !isset($_REQUEST['id'])) {
    die('Invalid usage');
}
$cid = $_REQUEST['cid'];
$id = $_REQUEST['id'];
$disposition = isset($_REQUEST['view']) && $_REQUEST['view'] ? 'inline' : 'attachment';
define('CID', $cid);
define('READ_ONLY_SESSION', true);
require_once '../../../include.php';
ModuleManager::load_modules();
if (!Acl::is_user()) {
    die('Permission denied');
}
$file = DB::GetRow('SELECT uaf.attach_id, uaf.original, uaf.filestorage_id FROM utils_attachment_file uaf WHERE uaf.id=%d', array($id));
$rec = Utils_RecordBrowserCommon::get_record('utils_attachment', $file['attach_id']);
if (!$rec) {
    die('Invalid attachment.');
}
$access_fields = Utils_RecordBrowserCommon::get_access('utils_attachment', 'view', $rec);
if (!isset($access_fields['note']) || !$access_fields['note']) {
    die('Access forbidden');
}
$original = $file['original'];
$local = $rec['id'];
$fsid = $file['filestorage_id'];
$crypted = $rec['crypted'];
$meta = Utils_FileStorageCommon::meta($fsid);
require_once 'mime.php';
if (headers_sent()) {
Example #16
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 #17
0
 public static function get_edit_details_modify_record($tab, $rid, $edit_id, $details = true)
 {
     self::init($tab);
     if (is_numeric($rid)) {
         $prev_rev = DB::GetOne('SELECT MIN(id) FROM ' . $tab . '_edit_history WHERE ' . $tab . '_id=%d AND id>%d', array($rid, $edit_id));
         $r = self::get_record_revision($tab, $rid, $prev_rev);
     } else {
         $r = $rid;
     }
     $edit_info = DB::GetRow('SELECT * FROM ' . $tab . '_edit_history WHERE id=%d', array($edit_id));
     $event_display = array('what' => 'Error, Invalid event: ' . $edit_id);
     if (!$edit_info) {
         return $event_display;
     }
     $event_display = array('who' => Base_UserCommon::get_user_label($edit_info['edited_by'], true), 'when' => Base_RegionalSettingsCommon::time2reg($edit_info['edited_on']), 'what' => array());
     $edit_details = DB::GetAssoc('SELECT field, old_value FROM ' . $tab . '_edit_history_data WHERE edit_id=%d', array($edit_id));
     self::init($tab);
     // because get_user_label messes up
     foreach ($r as $k => $v) {
         if (isset(self::$hash[$k]) && self::$table_rows[self::$hash[$k]]['type'] == 'multiselect') {
             $r[$k] = self::decode_multi($r[$k]);
         }
         // We have to decode all fields, because access and some display relay on it, regardless which field changed
     }
     $r2 = $r;
     foreach ($edit_details as $k => $v) {
         $k = self::get_field_id($k);
         // failsafe
         if (!isset(self::$hash[$k])) {
             continue;
         }
         if (self::$table_rows[self::$hash[$k]]['type'] == 'multiselect') {
             $v = $edit_details[$k] = self::decode_multi($v);
         }
         $r2[$k] = $v;
     }
     $access = self::get_access($tab, 'view', $r);
     $modifications_to_show = 0;
     foreach ($edit_details as $k => $v) {
         if ($k == 'id') {
             $modifications_to_show += 1;
             if (!$details) {
                 continue;
             }
             // do not generate content when we dont want them
             $event_display['what'] = _V($v);
             continue;
         }
         $k = self::get_field_id($k);
         // failsafe
         if (!isset(self::$hash[$k])) {
             continue;
         }
         if (!$access[$k]) {
             continue;
         }
         $modifications_to_show += 1;
         if (!$details) {
             continue;
         }
         // do not generate content when we dont want them
         self::init($tab);
         $field = self::$hash[$k];
         $params = self::$table_rows[$field];
         $event_display['what'][] = array(_V($params['name']), self::get_val($tab, $field, $r2, true, $params), self::get_val($tab, $field, $r, true, $params));
     }
     if ($modifications_to_show) {
         return $event_display;
     }
     return null;
 }
 public function get_record($id, $assoc = false)
 {
     global $E_SESSION;
     @(list($id, $pos) = explode('_', $id));
     if (!isset($pos)) {
         $pos = 0;
     }
     if ($pos >= 0) {
         $fields = DB::GetCol('SELECT field FROM company_field WHERE field LIKE \'%mail%\' ORDER BY field');
         if (!$fields) {
             return false;
         }
         if (!isset($fields[$pos])) {
             $pos = 0;
         }
         $m = 'f_' . preg_replace('/[^a-z0-9]/', '_', strtolower($fields[$pos]));
         $ret = DB::GetRow('SELECT id as ID,\'\' as firstname, \'\' as surname, f_company_name as name, ' . $m . ' as email FROM company_data_1 WHERE active=1 AND id=%d AND ' . $m . '!=\'\'  AND ' . $m . ' is not null AND (CAST(f_permission AS decimal)<2 OR created_by=%d)', array($id, $E_SESSION['user']));
     } else {
         $ret = DB::GetRow('SELECT id as ID,\'\' as firstname, \'\' as surname, f_company_name as name, (SELECT me.f_email FROM rc_multiple_emails_data_1 me WHERE me.id=%d) as email FROM company_data_1 WHERE active=1 AND id=%d AND (CAST(f_permission AS decimal)<2 OR created_by=%d)', array(-$pos, $id, $E_SESSION['user']));
     }
     if (!$ret) {
         return false;
     }
     if (!isset($ret['ID']) && isset($ret['id'])) {
         $ret['ID'] = $ret['id'];
     }
     $this->result = new rcube_result_set(1);
     $this->result->add($ret);
     if ($assoc) {
         return $ret;
     }
     return $this->result;
 }
Example #19
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;
 }
        }
        $alter_checkpoint->set('word_id', true);
    }
    if ($alter_checkpoint->get('tab_id', false) == false) {
        Patch::require_time(5);
        $b = DB::GetOne("SELECT\n            tc.constraint_name, tc.table_name, kcu.column_name,\n            ccu.table_name AS foreign_table_name,\n            ccu.column_name AS foreign_column_name\n        FROM\n            information_schema.table_constraints AS tc\n        JOIN information_schema.key_column_usage AS kcu\n          ON tc.constraint_name = kcu.constraint_name\n        JOIN information_schema.constraint_column_usage AS ccu\n          ON ccu.constraint_name = tc.constraint_name\n        WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name='recordbrowser_words_map' AND kcu.column_name='tab_id';");
        if ($b) {
            DB::StartTrans();
            DB::Execute('ALTER TABLE recordbrowser_words_map DROP CONSTRAINT "' . $b . '"');
            DB::Execute('ALTER TABLE recordbrowser_words_map ADD CONSTRAINT "' . $b . '" FOREIGN KEY (tab_id) REFERENCES recordbrowser_table_properties(id) ON DELETE CASCADE ON UPDATE CASCADE');
            DB::CompleteTrans();
        }
        $alter_checkpoint->set('tab_id', true);
    }
} elseif (DB::is_mysql()) {
    $a = DB::GetRow('SHOW CREATE TABLE recordbrowser_words_map');
    if ($alter_checkpoint->get('word_id', false) == false) {
        Patch::require_time(5);
        preg_match('/CONSTRAINT (.+) FOREIGN KEY .*word_id/', $a[1], $m);
        if (isset($m[1])) {
            DB::StartTrans();
            DB::Execute('ALTER TABLE recordbrowser_words_map DROP FOREIGN KEY ' . $m[1]);
            DB::Execute('ALTER TABLE recordbrowser_words_map ADD FOREIGN KEY (word_id) REFERENCES recordbrowser_words_index(id) ON DELETE CASCADE ON UPDATE CASCADE');
            DB::CompleteTrans();
        }
        unset($m);
        $alter_checkpoint->set('word_id', true);
    }
    if ($alter_checkpoint->get('tab_id', false) == false) {
        Patch::require_time(5);
        preg_match('/CONSTRAINT (.+) FOREIGN KEY .*tab_id/', $a[1], $m);
Example #21
0
 public static function get_record_by_email($email, $rset = null, $rid = null)
 {
     if ($rid == null) {
         $rset = null;
     }
     $cont = DB::GetRow('SELECT id, created_on, created_by FROM contact_data_1 WHERE active=1 AND f_email ' . DB::like() . ' %s AND id!=%d', array($email, $rset == 'contact' ? $rid : -1));
     if ($cont) {
         return array('contact', $cont['id']);
     }
     if (ModuleManager::is_installed('CRM_Roundcube') >= 0) {
         $vals = array($email);
         $where_id = '';
         if ($rid != null) {
             if ($rset == 'rc_multiple_emails') {
                 $vals[] = $rid;
                 $where_id = ' AND id!=%d';
             } else {
                 $vals[] = $rset;
                 $vals[] = $rid;
                 $where_id = ' AND (f_record_type!=%s OR f_record_id!=%d)';
             }
         }
         $tmp = DB::GetRow('SELECT id, f_record_id, f_record_type FROM rc_multiple_emails_data_1 WHERE active=1 AND f_email ' . DB::like() . ' %s' . $where_id . ' ORDER BY f_record_type DESC', $vals);
         if ($tmp) {
             return array($tmp['f_record_type'], $tmp['f_record_id']);
         }
     }
     $comp = DB::GetRow('SELECT id, created_on, created_by FROM company_data_1 WHERE active=1 AND f_email ' . DB::like() . ' %s AND id!=%d', array($email, $rset == 'company' ? $rid : -1));
     if ($comp) {
         return array('company', $comp['id']);
     }
     return false;
 }
Example #22
0
    public static function save_google_docs($note_id) {
        $edit_url = DB::GetOne('SELECT doc_id FROM utils_attachment_googledocs WHERE note_id = %d', array($note_id));
        if (!$edit_url) {
            Base_StatusBarCommon::message(__('Document not found'), 'warning');
            return false;
        }
        if(!preg_match('/(spreadsheet|document)%3A(.+)$/i',$edit_url,$matches)) {
            Base_StatusBarCommon::message(__('Document not found'), 'warning');
            return false;
        }
        $edit_url = $matches[2];
        $doc = $matches[1]=='document';
        if ($doc)
            $export_url = 'https://docs.google.com/feeds/download/documents/Export?id='.$edit_url.'&exportFormat=doc';
        else
            $export_url = 'https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key='.$edit_url.'&exportFormat=xls';

        DB::Execute('DELETE FROM utils_attachment_googledocs WHERE note_id = %d', array($note_id));
        $g_auth = Utils_AttachmentCommon::get_google_auth(null, null, $doc?'writely':'wise');
        $curl = curl_init();

        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

        $headers = array(
            "Authorization: GoogleLogin auth=" . $g_auth,
            "If-Match: *",
            "GData-Version: 3.0",
        );
        curl_setopt($curl, CURLOPT_URL, $export_url);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_POST, false);
        $response = curl_exec_follow($curl);

        $row = DB::GetRow('SELECT f.*,l.f_crypted as crypted FROM utils_attachment_file f INNER JOIN utils_attachment_data_1 l ON l.id=f.attach_id WHERE f.id=%d',array($note_id));

        $local = DATA_DIR.'/Utils_Attachment/temp/'.Acl::get_user().'/gdocs';
        @mkdir($local,0777,true);
        $dest_file = $local.'/'.$row['id'];

        if($row['crypted']) {
            $password = $_SESSION['client']['cp'.$row['attach_id']];
            $response = Utils_AttachmentCommon::encrypt($response,$password);
        }
        file_put_contents($dest_file, $response);
        if($doc) {
            $ext = 'docx';
        } else $ext = 'xlsx';

        $row['original'] = substr($row['original'],0,strrpos($row['original'],'.')).'.'.$ext;

        Utils_AttachmentCommon::add_file($row['attach_id'], Acl::get_user(), $row['original'], $dest_file);
        DB::Execute('UPDATE utils_attachment_file SET deleted=1 WHERE id=%d',array($row['id']));

        $headers = array(
            "Authorization: GoogleLogin auth=" . $g_auth,
            "If-Match: *",
            "GData-Version: 3.0",
        );
        curl_setopt($curl, CURLOPT_URL, $edit_url);
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($curl, CURLOPT_POST, false);
        $response = curl_exec($curl);

        Base_StatusBarCommon::message(__('Changes saved'));
    }
Example #23
0
 public function get_new_event_href_js($timestamp, $timeless)
 {
     if ($this->lp == null) {
         // $this->lp is null only then there's one module providing events with one event type
         $handler = DB::GetRow('SELECT id, group_name, handler_callback FROM crm_calendar_custom_events_handlers');
         if (!$handler) {
             return false;
         }
         $handler['handler_callback'] = explode('::', $handler['handler_callback']);
         $new_events = call_user_func($handler['handler_callback'], 'new_event_types');
         if ($new_events === null || empty($new_events)) {
             return false;
         }
         foreach ($new_events as $k => $w) {
             if (!is_array($w)) {
                 $w = array('label' => $w, 'icon' => null);
             }
             if (isset($_REQUEST['create_new_event'])) {
                 unset($_REQUEST['create_new_event']);
                 $this->jump_to_new_event($_REQUEST['option'], $_REQUEST['timestamp'], $_REQUEST['timeless']);
                 return;
             }
             return $this->create_href_js(array('create_new_event' => true, 'option' => 'new_event__' . $handler['id'] . '__' . $k, 'timestamp' => $timestamp, 'timeless' => $timeless));
         }
     }
     return $this->lp->get_href_js(array($timestamp, $timeless));
 }
Example #24
0
 public static function set_id($id)
 {
     $c = DB::GetRow('SELECT max(page_id) as max,min(page_id) as min FROM history WHERE session_name=%s AND client_id=%d', array(self::session_id(), CID));
     if ($id < 1 || $id < $c['min']) {
         $id = $c['min'];
     } elseif ($id > $c['max']) {
         $id = $c['max'];
     }
     $_SESSION['client']['__history_id__'] = intval($id);
     $data = DB::GetOne('SELECT data FROM history WHERE session_name=%s AND client_id=%d AND page_id=%d', array(self::session_id(), CID, $_SESSION['client']['__history_id__'] - 1));
     if ($data === false) {
         Epesi::alert('History expired.');
         return;
     }
     //		$data = DB::BlobDecode($data);
     if (GZIP_HISTORY && function_exists('gzuncompress')) {
         $data = gzuncompress($data);
     }
     $_SESSION['client']['__module_vars__'] = unserialize($data);
 }
Example #25
0
    die('Invalid request');
}
define('CID', false);
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['mail_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');
}
list($mimetype, $name, $attachment) = DB::GetRow('SELECT type,name,attachment FROM rc_mails_attachments WHERE mail_id=%d AND mime_id=%s', array($_GET['mail_id'], $_GET['mime_id']));
$disposition = $attachment ? 'attachment' : 'inline';
$filename = DATA_DIR . '/CRM_Roundcube/attachments/' . $_GET['mail_id'] . '/' . $_GET['mime_id'];
if (headers_sent()) {
    die('Some data has already been output to browser, can\'t send file');
}
if (!file_exists($filename)) {
    die('File doesn\'t exists');
}
$buffer = file_get_contents($filename);
header('Content-Type: ' . $mimetype);
header('Content-Length: ' . strlen($buffer));
header('Content-disposition: ' . $disposition . '; filename="' . $name . '"');
echo $buffer;
Example #26
0
 * @package epesi-utils
 * @subpackage attachment
 */
if (!isset($_REQUEST['token']) || !isset($_REQUEST['id'])) {
    die('Invalid usage');
}
$id = $_REQUEST['id'];
$token = $_REQUEST['token'];
define('CID', false);
define('READ_ONLY_SESSION', true);
require_once '../../../include.php';
ModuleManager::load_modules();
$query = 'SELECT ual.id as aid,uaf.id,uaf.filestorage_id,uaf.attach_id,uaf.original,uad.ip_address,uad.attach_file_id,uad.created_by,uad.created_on,uad.description FROM (utils_attachment_file uaf INNER JOIN utils_attachment_download uad ON uad.attach_file_id=uaf.id) INNER JOIN utils_attachment_data_1 ual ON uaf.attach_id=ual.id WHERE uad.id=' . DB::qstr($id) . ' AND uad.token=' . DB::qstr($token) . ' AND uad.expires_on>' . DB::DBTimeStamp(time()) . ' AND uad.remote=';
$row = DB::GetRow($query . '1');
if ($row == false) {
    $row = DB::GetRow($query . '2');
    if ($row == false) {
        die('No such file');
    }
    $duplicate = true;
} else {
    $duplicate = false;
}
$original = $row['original'];
$file_id = $row['id'];
$local = $row['aid'];
$fsid = $row['filestorage_id'];
$filename = $local . '/' . $file_id;
if (headers_sent()) {
    die('Some data has already been output to browser, can\'t send file');
}
Example #27
0
 protected function perform_update_start()
 {
     $this->turn_on_maintenance_mode();
     //restore innodb tables in case of db reimport
     if (DB::is_mysql()) {
         $tbls = DB::MetaTables('TABLE', true);
         foreach ($tbls as $t) {
             $tbl = DB::GetRow('SHOW CREATE TABLE ' . $t);
             if (!isset($tbl[1]) || preg_match('/ENGINE=myisam/i', $tbl[1])) {
                 DB::Execute('ALTER TABLE ' . $t . ' ENGINE = INNODB');
             }
         }
     }
 }
Example #28
0
 public static function send_email_notifications($event_id)
 {
     $event = DB::GetRow('SELECT * FROM utils_watchdog_event WHERE id=%d', array($event_id));
     if (!$event) {
         return;
     }
     $category_id = $event['category_id'];
     $id = $event['internal_id'];
     $message = $event['message'];
     $subscribers = self::get_subscribers($category_id, $id);
     $c_user = Acl::get_user();
     self::email_mode(true);
     foreach ($subscribers as $user_id) {
         $wants_email = Base_User_SettingsCommon::get('Utils_Watchdog', 'email', $user_id);
         if (!$wants_email) {
             continue;
         }
         Acl::set_user($user_id);
         Base_LangCommon::load();
         $email_data = self::display_events($category_id, array($event_id => $message), $id, true);
         if (!$email_data) {
             continue;
         }
         $contact = Utils_RecordBrowserCommon::get_id('contact', 'login', $user_id);
         if (!$contact) {
             continue;
         }
         $email = Utils_RecordBrowserCommon::get_value('contact', $contact, 'email');
         if (!$email) {
             continue;
         }
         $title = __('%s notification - %s - %s', array(EPESI, $email_data['category'], strip_tags($email_data['title'])));
         Base_MailCommon::send($email, $title, $email_data['events'], null, null, true);
     }
     Acl::set_user($c_user);
     Base_LangCommon::load();
     self::email_mode(false);
 }
Example #29
0
 protected function perform_update_start()
 {
     $this->cli_msg("Update from " . $this->system_version . " to " . $this->current_version . "...");
     $this->turn_on_maintenance_mode();
     //restore innodb tables in case of db reimport
     $mysql = stripos(DATABASE_DRIVER, 'mysql') !== false;
     if ($mysql) {
         $tbls = DB::MetaTables('TABLE', true);
         foreach ($tbls as $t) {
             $tbl = DB::GetRow('SHOW CREATE TABLE ' . $t);
             if (!isset($tbl[1]) || preg_match('/ENGINE=myisam/i', $tbl[1])) {
                 DB::Execute('ALTER TABLE ' . $t . ' ENGINE = INNODB');
             }
         }
     }
 }
Example #30
0
 public static function get_default_currency()
 {
     static $cache = null;
     if ($cache === null) {
         $cache = DB::GetRow('SELECT * FROM utils_currency WHERE default_currency=1');
     }
     return $cache;
 }