/**
   * 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);  
  }
Beispiel #2
0
  function getOBMId($attendee, $entity) {
    global $cdg_sql;

    $db = new DB_OBM;
    $db_type = $obm_q->type;
    if(!is_null($attendee['cn'])) {
      $this->cns[$entity][$attendee['cn']] = NULL;
      $cn = "OR cn = '".addslashes($attendee['cn'])."'";
    }
    if(!is_null($attendee['mail'])) {
      $this->mails[$entity][$attendee['mail']] = NULL;
      $mail = "OR mail #LIKE '%".addslashes($attendee['mail'])."%' ";
    }
    if(!$mail && !$cn) {
      return NULL;
    }
    $entityTable = $this->buildEntityQuery($entity, $db);
    if(is_null($entityTable)) {
      return NULL;
    }
    $query = 'SELECT id, mail, cn
              FROM ('.$entityTable.') as Entity WHERE (1 = 0 '.$cn.' '.$mail.') 
              AND domain_id '.sql_parse_id($GLOBALS['obm']['domain_id'], true).'
              GROUP BY id, mail, cn';
    display_debug_msg($query, $cdg_sql, 'getOBMId');
    $db->xquery($query);
    while($db->next_record()) {
      if((!is_null($attendee['cn']) && strtolower($db->f('cn')) == $attendee['cn']) ||
         preg_match_all('/^('.($attendee['mail']).'|'.$attendee['email'].')\r?$/mi',$db->f('mail'),$results)) { 
        $this->cns[strtolower($db->f('cn'))][$entity] = $db->f('id');
        $emails = get_entity_email($db->f('mail'),null,true,null);
        foreach($emails as $email) {
          $this->mails[strtolower($email)][$entity] = $db->f('id');
        } 
        return  $db->f('id');
      }
    }
    return NULL;
  }
Beispiel #3
0
 /**
  * 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);
 }
Beispiel #4
0
 function parseCategories($categories) {
   if(is_null($categories)) {
     return NULL;
   }
   $name = addslashes(array_shift($categories));
   $query = "SELECT eventcategory1_id as id FROM EventCategory1 WHERE
     eventcategory1_label = '$name' AND 
     eventcategory1_domain_id ".sql_parse_id($GLOBALS['obm']['domain_id'], true);
   $this->db->query($query);
   if($this->db->next_record()) {
     return $this->db->f('id');
   }
   return NULL;
 }
Beispiel #5
0
  /**
   * Get event owner email address
   */
  protected function getOwner($event) {
    global $obm, $cdg_sql;

    $owner_label = $event->owner->label;
    $owner_id = sql_parse_id($event->owner->id, true);
    $query = "SELECT 
    userobm_email, domain_name
    FROM UserObm
    INNER JOIN Domain ON userobm_domain_id = domain_id
    WHERE userobm_id $owner_id";

    display_debug_msg($query, $cdg_sql, 'run_query_get_sender()');
    $db = new DB_OBM;
    $db->query($query);
    $db->next_record();
    
    $email = $this->getEntityEmail($db->f('userobm_email'), $db->f('domain_name'));
    if(!$email) $email = $this->getEntityEmail('noreply');
    return $email;
  }
Beispiel #6
0
 /**
  * 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']);
 }
Beispiel #7
0
  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;
    }
  }