/** * standard constructor * @access public **/ public function __construct($user = '') { global $cdg_sql; if (empty($user)) { $user = '******'; } $obm_q = new DB_OBM(); $query = "SELECT usersystem_password as password FROM UserSystem WHERE usersystem_login='******'"; display_debug_msg($query, $cdg_sql, "SatelliteCredentials::__construct()"); $obm_q->query($query); if (!$obm_q->next_record()) { throw new Exception("Can't find {$user} system user"); } //else parent::__construct($user, $obm_q->f('password')); }
echo "Unknown options \n"; exit; } elseif (!isset($options['w']) || !isset($options['e']) || !isset($options['t'])) { echo "-wet do delete -dry for dry run. You must specified one of this two options\n"; exit; } if (is_numeric($options['u'])) { $userobm = "WHERE userobm_id = {$options['u']}"; } $query = "SELECT userobm_id, userobm_login, id, name from UserObm INNER JOIN AddressBook ON owner = userobm_id {$userobm} GROUP BY userobm_id"; $obm_q = new DB_OBM(); $obm_q->query($query); $obm_q2 = new DB_OBM(); while ($obm_q->next_record()) { $query = "SELECT \n contact_id, contact_lastname, contact_firstname, \n e1.email_address as contact_email,\n e2.email_address as contact_email2,\n WorkPhone.phone_number as contact_phone,\n MobilePhone.phone_number as contact_mobilephone,\n HomePhone.phone_number as contact_homephone,\n contact_archive,\n OtherPhone.phone_number as contact_otherphone\n FROM Contact \n INNER JOIN ContactEntity ON contactentity_contact_id = contact_id\n LEFT JOIN Email e1 ON e1.email_entity_id = contactentity_entity_id AND e1.email_label = 'INTERNET;X-OBM-Ref1'\n LEFT JOIN Email e2 ON e2.email_entity_id = contactentity_entity_id AND e2.email_label = 'INTERNET;X-OBM-Ref1'\n LEFT JOIN Phone as WorkPhone ON WorkPhone.phone_entity_id = contactentity_entity_id AND WorkPhone.phone_label = 'WORK;VOICE;X-OBM-Ref1'\n LEFT JOIN Phone as MobilePhone ON MobilePhone.phone_entity_id = contactentity_entity_id AND MobilePhone.phone_label = 'CELL;VOICE;X-OBM-Ref1'\n LEFT JOIN Phone as HomePhone ON HomePhone.phone_entity_id = contactentity_entity_id AND HomePhone.phone_label = 'HOME;VOICE;X-OBM-Ref1'\n LEFT JOIN Phone as OtherPhone ON OtherPhone.phone_entity_id = contactentity_entity_id AND OtherPhone.phone_label = 'OTHER;VOICE;X-OBM-Ref1'\n WHERE contact_addressbook_id = " . $obm_q->f('id') . " \n ORDER BY contact_id"; $obm_q2->query($query); echo "===================================================\n"; echo "For user " . $obm_q->f('userobm_login') . " (" . $obm_q->f('userobm_id') . "), Addressbook " . $obm_q->f('name') . " (" . $obm_q->f('id') . ") : " . $obm_q2->nf() . " contacts\n"; $contacts = array(); while ($obm_q2->next_record()) { $datas = array_map('clean_values', $obm_q2->Record); $contacts[$obm_q2->f('contact_id')] = $datas; } $duples = array_duples($contacts); echo count($duples) . " contacts to delete\n"; if (count($duples) > 0 && !$dry) { $query = "INSERT INTO DeletedContact SELECT contact_id, contact_usercreate, NOW() , 'kill' FROM Contact WHERE contact_id IN (" . implode(',', $duples) . ")"; $obm_q2->query($query); } } if (!$dry) {
/** * disableVacation * * @param mixed $users * @access public * @return void */ function disableVacation($users) { if(count($users) > 0) { $this->logger->debug("Disabling ".count($users)."vacations in main table"); $obm_q = new DB_OBM; $query = "UPDATE UserObm set userobm_vacation_enable = 0, userobm_vacation_datebegin = NULL, userobm_vacation_dateend = NULL WHERE userobm_id IN (".implode(',',array_keys($users)).")"; $this->logger->core($query); $obm_q->query($query); $this->logger->debug("Disabling ".count($users)."vacations in P table"); $obm_q = new DB_OBM; $query = "UPDATE P_UserObm set userobm_vacation_enable = 0, userobm_vacation_datebegin = NULL, userobm_vacation_dateend = NULL WHERE userobm_id IN (".implode(',',array_keys($users)).")"; $this->logger->core($query); $obm_q->query($query); $disable = array(); foreach ($users as $id => $user) { if($user['enable'] == 0) { $this->logger->warn("User $login domain : $domain vacation is set to be disabled but is already disabled. Noting will be done."); } else { $disable[$id] = $user; } } $this->logger->debug("Disabling ".count($users)."vacations in sieve"); if(count($disable) > 0) $this->updateVacation($disable); } }
function get_document_mime_type($id) { global $cdg_sql; $query = "SELECT documentmimetype_extension FROM Document JOIN DocumentMimeType ON document_mimetype_id = documentmimetype_id WHERE document_id = '$id'"; display_debug_msg($query, $cdg_sql); $obm_q = new DB_OBM; $obm_q->query($query); if ($obm_q->num_rows() == 1){ $obm_q->next_record(); return $obm_q->f("documentmimetype_extension"); } else return ""; }
public function getValue($entity_id) { $id = of_entity_get($this->entity, $entity_id); $db = new DB_OBM(); $query = "SELECT * FROM field WHERE entity_id = '$id'"; $db->query($query); $ret = array(); while($db->next_record()) { $f = $db->f('field'); if ($this->fields[$f]['type'] == "boolean") { $ret[$f] = $db->f('value') == 1 ? $GLOBALS['l_yes']:$GLOBALS['l_no']; } else { $ret[$f] = $db->f('value'); } } return $ret; }
function check_insert_admin0() { global $cdg_sql; $obm_q = new DB_OBM; // Check if adomain 0 admin is present $q = "Select userobm_id FROM UserObm WHERE userobm_domain_id=0"; $obm_q->query($q); if ($obm_q->num_rows() > 0) { echo "\nDomain 0 admin : yes\n"; } else { echo "\nDomain 0 admin : no : insertion..."; $q = "INSERT INTO UserObm ( userobm_domain_id, userobm_login, userobm_password, userobm_password_type, userobm_perms, userobm_lastname, userobm_firstname, userobm_uid, userobm_gid) VALUES ( 0, 'admin0', 'admin', 'PLAIN', 'admin', 'Admin Lastname', 'Firstname', '1000', '512')"; $obm_q->query($q); echo "OK\n"; } }
/** * get the details for entity of type mailshare * @param int $mailshare_id * @access protected */ protected function mailshareDetails($mailshare_id) { $obm_q = new DB_OBM(); $db_type = $obm_q->type; $multidomain = sql_multidomain('mailshare'); $id = sql_parse_id($mailshare_id, true); $query = "SELECT\n mailshare_id as id,\n mailshare_name as login,\n 'mailshare' as entity,\n domain_name as realm,\n ms.host_ip as host\n FROM MailShare\n LEFT JOIN Domain on mailshare_domain_id=domain_id\n LEFT JOIN Host ms on mailshare_mail_server_id=ms.host_id\n WHERE mailshare_id {$id} \n {$multidomain}"; display_debug_msg($query, $GLOBALS['cdg_sql'], 'Backup::mailshareDetails()'); $obm_q->query($query); if (!$obm_q->next_record()) { throw new Exception($GLOBALS['l_err_reference']); } $this->details = $obm_q->Record; $this->details['login'] = strtolower($this->details['login']); }
/** * Delete all attributes stored into the database * @access protected **/ protected function purgeAttributes() { global $cdg_sql; $obm_q = new DB_OBM(); $id = sql_parse_id($this->id, true); $query = "DELETE FROM userpattern_property WHERE userpattern_id {$id}"; display_debug_msg($query, $cdg_sql, "UserPattern::purgeAttributes()"); $obm_q->query($query); }
function reportMailProgress ($campaign_id, $nb_in_queue, $nb_sent, $nb_error) { $obm_q = new DB_OBM; if ($nb_in_queue == 0) { $query = "UPDATE Campaign SET campaign_status = " . $this->campaign_status_enum['finished'] . ", campaign_progress = 100 WHERE campaign_id = " . $campaign_id . ";"; } else { $query = "UPDATE Campaign SET campaign_progress = " . round(($nb_sent + $nb_error) / ($nb_sent + $nb_error + $nb_in_queue) * 100) . " WHERE campaign_id = " . $campaign_id . ";"; } $obm_q->query($query); }
static function resourceExist($id) { $db = new DB_OBM; $query = 'SELECT resource_id From Resource WHERE resource_id = '.$id; $db->query($query); return $db->next_record(); }
// Check if banned words are included $excluded_words = array ('insert', 'update', 'delete', 'create', 'alter', 'drop', 'lock', 'userobm_password'); while ( list($key, $value) = each($excluded_words) ) { if (preg_match("/\b$value\b/i", $query)) { $err['msg'] = "$l_err_query_banned $l_banned_word : $value"; echo $err['msg']; return false; } } $prefs = get_display_pref($obm['uid'], $entity); display_debug_msg($query, $cdg_sql, 'export()'); $obm_q = new DB_OBM; $obm_q->query($query); // Set separator (if not set in setting => ;) if (($_SESSION['set_csv_sep'] != $ccsvd_sc) && ($_SESSION['set_csv_sep'] != $ccsvd_tab)) { $sep = ';'; } else if ($_SESSION['set_csv_sep'] == $ccsvd_tab) { $sep = "\t"; } else { $sep = $_SESSION['set_csv_sep']; } $export_d = new OBM_DISPLAY('DATA', $prefs, $emodule); $export_d->display_entity = "$entity"; $export_d->data_set = $obm_q; header('Content-Type: text/comma-separated-values'); header("Content-Disposition: attachment; filename=\"$entity.csv\"");
function process_list_list() { global $clist_mode_normal, $clist_mode_expert, $lists; $cpt_list_ok = 0; $cpt_list_err = 0; $cpt_list = count($lists); $txt = "\n***** Traitement des listes"; $log .= $txt; echo $txt; $obm_q = new DB_OBM; $nb_lists = count($lists); $cpt = 0; foreach ($lists as $id => $l) { $cpt++; $query = ''; // get the list query if ($l['mode'] == $clist_mode_normal) { if ($l['structure'] != '') { $criteria = unserialize($l['structure']); if ($criteria != '') { $as_criteria = $criteria; if (is_array($as_criteria)) { array_walk($as_criteria, 'list_add_slashes_array'); } $l['criteria'] = $as_criteria; $dynlist = make_list_query_from_criteria($l); $query = $dynlist['query']; } } // expert mode } else { $query = $l['query']; } $obm_q->query($query); process_one_list($l, $obm_q, $nb_lists, $cpt); } echo "\n***** Fin traitement des listes"; $txt .= "\n\n"; $log .= $txt; echo $txt; }
/** * __construct * * @access public * @return void */ public function __construct() { include $GLOBALS['realPath']."/firstnames.php"; $db = new DB_OBM; foreach($firstnames as $key => $firstname) { $db->query("INSERT INTO firstnames (data1,data2,data3) VALUES ('".addslashes($firstname)."','".addslashes($firstnames[$key+1])."','".addslashes($firstnames[$key-1])."')"); if($key > 4998) break; } include $GLOBALS['realPath']."/lastnames.php"; foreach($lastnames as $key => $lastname){ $db->query("INSERT INTO lastnames (data1,data2,data3) VALUES ('".addslashes($lastname)."','".addslashes($lastnames[$key+1])."','".addslashes($lastnames[$key-1])."')"); if($key > 4998) break; } include $GLOBALS['realPath']."/words.php"; foreach($words as $key => $word) { $db->query("INSERT INTO words (data1,data2,data3) VALUES ('".addslashes($word)."','".addslashes($words[$key+1])."','".addslashes($words[$key-1])."')"); if($key > 4998) break; } include $GLOBALS['realPath']."/texts.php"; foreach($texts as $key => $text){ $db->query("INSERT INTO texts (data1,data2,data3) VALUES ('".addslashes($text)."','".addslashes($texts[$key+1])."','".addslashes($texts[$key-1])."')"); if($key > 4998) break; } $this->firstnames = array('firstnames', 5000); $this->lastnames = array('lastnames', 841); $this->texts = array('texts',101); $this->words = array('words', 241); }
/** * getAlertDelta * * @param mixed $id * @access public * @return void */ function getAlertDelta($id, $user_id) { $query = "SELECT eventalert_duration FROM EventAlert WHERE eventalert_event_id = '$id' AND eventalert_user_id = $user_id"; $obm_q = new DB_OBM; $this->logger->core($query); $obm_q->query($query); $obm_q->next_record(); $this->logger->debug("Reminder delta for event ".$id." is ".$obm_q->f('eventalert_duration')." seconds"); return $obm_q->f('eventalert_duration'); }
function getEventAttendees($eventId){ $db = new DB_OBM; $query = "SELECT userobm.* FROM event INNER JOIN eventlink ON event.event_id = eventlink.eventlink_event_id INNER JOIN userentity ON eventlink.eventlink_entity_id = userentity.userentity_entity_id INNER JOIN userobm ON userentity.userentity_user_id = userobm.userobm_id WHERE event_id = '".$eventId."'"; $db->query($query); if($db->nf() == 0) return null; $attendees = array(); while($db->next_record()){ $attendees[$db->f("userobm_id")] = $this->db->Record; } return $attendees; }
/** * Get recipients email addresses * * $recipients : Id Recipients array * $setting : recipient setting to check (set_mail, set_mail_participant) * $force : Mail should be forced (all user even with no set_mail) * Returns: DB with email recipients, or false if no valid recipients */ protected function getRecipients($recipients, $setting='set_mail', $force=false) { global $cdg_sql; if (($setting == 'set_mail') || ($setting == 'set_mail_participation')) { $set_mail = $setting; } else { $set_mail = 'set_mail'; } if (!$force) { $mail_filter = " AND (up1.userobmpref_value = 'yes' OR (up2.userobmpref_value = 'yes' AND up1.userobmpref_value IS NULL))"; $join = "LEFT JOIN UserObmPref as up1 ON up1.userobmpref_user_id=userobm_id AND up1.userobmpref_option = '$set_mail' LEFT JOIN UserObmPref as up2 on up2.userobmpref_user_id IS NULL AND up2.userobmpref_option = '$set_mail'"; } $coma = ''; foreach($recipients as $recipient) { if ($recipient) { $user_list .= $coma.$recipient; $coma = ','; } } if ($user_list != '') { $user_in = "userobm_id IN ($user_list) AND"; } else { return false; } $query = "SELECT userobm_email, userobm_lastname, userobm_firstname, userobm_commonname, domain_name FROM UserObm INNER JOIN Domain on userobm_domain_id = domain_id $join WHERE $user_in userobm_email != '' $mail_filter"; display_debug_msg($query, $cdg_sql, 'run_query_get_recipients()'); $db = new DB_OBM; $db->query($query); $recipients = array(); while ($db->next_record()) { $email = $this->getEntityEmail($db->f('userobm_email'), $db->f('domain_name')); $displayname = $db->f('userobm_commonname'); if (!$displayname) $displayname = sprintf($GLOBALS['l_displayname_template'], $db->f('userobm_firstname'), $db->f('userobm_lastname')); if (isset($email) && $email != "") { $recipients[] = array($email, $displayname); } } return $recipients; }
public function reset() { if ($this->name!='public_contacts' && $this->admin) { $db = new DB_OBM; // Delete contacts $query = "DELETE FROM Contact WHERE contact_addressbook_id='$this->id'"; $db->query($query); // Delete solr OBM_IndexingService::deleteByQuery('contact', "addressbookId:$this->id"); } }
/** * Delete a contact * * @param Integer $c_id contact_id * @return Boolean */ function DeleteContact($c_id) { global $cdg_sql, $c_use_connectors; $sql_id = sql_parse_id($c_id, true); $this->logger->debug("Delete contact $c_id"); $obm_q = new DB_OBM; $query = "SELECT contact_company_id, contact_birthday_id, contact_usercreate, contact_addressbook_id FROM Contact WHERE contact_id $sql_id"; $this->logger->core($query); $obm_q->query($query); $obm_q->next_record(); $comp_id = $obm_q->f('contact_company_id'); $birthday_id = $obm_q->f('contact_birthday_id'); $uid = $obm_q->f('contact_usercreate'); $ad = $obm_q->f('contact_addressbook_id'); // Hook : Pre if (function_exists('hook_pre_run_query_contact_delete')) { if (! hook_pre_run_query_contact_delete($c_id)) { return false; } } run_query_global_delete_document_links($c_id, 'contact'); $ret = of_userdata_query_delete('contact', $c_id); // BEGIN birthday support $query = "DELETE FROM Event WHERE event_id = '$birthday_id'"; $this->logger->core($query); $obm_q->query($query); // END birthday support of_entity_delete('contact', $c_id); $query = "DELETE FROM Contact WHERE contact_id $sql_id"; $this->logger->core($query); $obm_q->query($query); // If connectors in use if ($c_use_connectors) { $query = "INSERT INTO DeletedContact (deletedcontact_contact_id, deletedcontact_addressbook_id, deletedcontact_timestamp, deletedcontact_origin) VALUES ($c_id, $ad, NOW(), '$GLOBALS[c_origin_cron]')"; $this->logger->core($query); $obm_q->query($query); } // After contact deletion to get correct number run_query_global_company_contact_number_update($comp_id); // Delete index OBM_IndexingService::delete('contact', $c_id); }
protected function getDomains() { $domains = array(); $obm_q = new DB_OBM(); $query = "SELECT domain_id FROM Domain WHERE domain_global=0"; $this->logger->core($query); $obm_q->query($query); while ($obm_q->next_record()) { $domains[] = $obm_q->f('domain_id'); } return $domains; }
private static function storeAnniversary($date='birthday', $contact_id, $contact_usercreate, $event_id, $contact_fullname, $old_value, $new_value) { global $cdg_sql, $obm; global $l_birthday_event_title, $l_anniversary_event_title; list($nope_event, $insert_event, $update_event, $delete_event) = array(0,1,2,3); if ($event_id == null) { if ($new_value != null) { $do = $insert_event; } } else { if ($new_value == null) { $do = $delete_event; } else if ($new_value->compare($old_value) != 0) { $do = $update_event; } } $obm_q = new DB_OBM; $multidomain_contact = sql_multidomain('contact'); $multidomain_event = sql_multidomain('event'); switch ($do) { case $insert_event: $duration = 3600*24; $label = ${"l_${date}_event_title"}; $title = str_replace('\'', '\\\'', sprintf($label, $contact_fullname)); $ext_id = get_obm_info('product_id').sha1(uniqid()).sha1($GLOBALS['obm']['domain_name']).sha1(mktime()*rand()); $query = "INSERT INTO Event (event_timeupdate, event_timecreate, event_usercreate, event_origin, event_owner, event_ext_id, event_timezone, event_title, event_date, event_description, event_properties, event_location, event_category1_id, event_priority, event_privacy, event_duration, event_repeatkind, event_repeatfrequence, event_repeatdays, event_allday, event_color, event_endrepeat, event_domain_id, event_opacity) VALUES ( NOW(), NOW(), '$contact_usercreate', '$GLOBALS[c_origin_web]', '$contact_usercreate', '$ext_id', '".Of_Date::getOption('timezone')."', '$title', '$new_value', '', '', '', NULL, '2', '0', '$duration', 'yearly', '1', '0000000', '1', '', NULL, '$obm[domain_id]', 'TRANSPARENT')"; $obm_q->query($query); display_debug_msg($query, $cdg_sql, 'run_query_contact_birthday_update(insert event)'); $insert_event_id = $obm_q->lastid(); if ($insert_event_id) { of_entity_insert('event', $insert_event_id); $sql_id = sql_parse_id($contact_id); $query = "UPDATE Contact SET contact_${date}_id = $insert_event_id WHERE contact_id = $sql_id $multidomain_contact"; $obm_q->query($query); display_debug_msg($query, $cdg_sql, "run_query_contact_birthday_update(update birthday id)"); $entity_id = of_entity_get('user', $contact_usercreate); $query = "INSERT INTO EventLink ( eventlink_timecreate, eventlink_usercreate, eventlink_event_id, eventlink_entity_id, eventlink_state) VALUES ( NOW(), $contact_usercreate, $insert_event_id, $entity_id, 'ACCEPTED')"; $obm_q->query($query); display_debug_msg($query, $cdg_sql, "run_query_contact_birthday_update(insert entity)"); } break; case $update_event: $sql_id = sql_parse_id($event_id); $query = "UPDATE Event SET event_date = '$new_value', event_origin = '$GLOBALS[c_origin_web]' WHERE event_id = $sql_id $multidomain_event"; $obm_q->query($query); display_debug_msg($query, $cdg_sql, 'run_query_contact_birthday_update(update event)'); break; case $delete_event: of_entity_delete('event',$event_id); $sql_id = sql_parse_id($event_id); $query = "DELETE FROM Event WHERE event_id = $sql_id $multidomain_event"; $obm_q->query($query); display_debug_msg($query, $cdg_sql, 'run_query_contact_birthday_update(delete event)'); break; } }