Ejemplo n.º 1
0
 /**
  * 检查分组名是否存在
  * @param $user_id 联系人ID
  * @param $name 分组名
  * @param $id 分组ID
  * @return bool
  */
 public function check_category_name($user_id, $name, $id)
 {
     $filter = '';
     if (!empty($id)) {
         $filter = "AND id != {$id}";
     }
     $sql = sprintf("SELECT id FROM %s WHERE uid = %d AND category_name = %s %s LIMIT 1", $this->get_table($user_id, 'contact_categories'), $user_id, $this->db->escape($name), $filter);
     $query = $this->db->query($sql);
     if ($query->count()) {
         return TRUE;
     }
     return FALSE;
 }
Ejemplo n.º 2
0
 /**
  * 添加电话、邮箱、网址、纪念日、关系、地址等信息
  * @param int $group_id 用户ID
  * @param int $id 联系人分组ID
  * @param int $type 类型
  * @param array $emails 邮箱信息
  * @return array
  */
 private function _add_info($group_id, $id, $type = 'emails', $values, $pref_tel = '')
 {
     $sql = array();
     switch ($type) {
         case 'tels':
             if (!empty($values)) {
                 foreach ($values as $tel) {
                     if (!empty($tel['value'])) {
                         if ($pref_tel and ($tel['value'] == $pref_tel or $tel['pref'] == 1)) {
                             continue;
                         }
                         if ($tel['pref'] == 1) {
                             $pref_tel = $tel['value'];
                         }
                         $tel['type'] = $this->db->escape($tel['type']);
                         $tel['value'] = $this->db->escape($tel['value']);
                         $tel['city'] = $this->db->escape($tel['city']);
                         $sql[] = "INSERT INTO `gcp_tels` (`gid`, `gcid`, `type`, `value`," . " `pref`, `city`) VALUES ('{$group_id}', '{$id}', {$tel['type']} ,{$tel['value']}," . " {$tel['pref']}, {$tel['city']});";
                     }
                 }
             }
             break;
         case 'addresses':
             if (!empty($values)) {
                 foreach ($values as $address) {
                     if (!empty($address['country']) || !empty($address['region']) || !empty($address['city']) || !empty($address['street']) || !empty($address['postal'])) {
                         $address['country'] = $this->db->escape($address['country']);
                         $address['region'] = $this->db->escape($address['region']);
                         $address['city'] = $this->db->escape($address['city']);
                         $address['street'] = $this->db->escape($address['street']);
                         $address['postal'] = $this->db->escape($address['postal']);
                         $address['type'] = $this->db->escape($address['type']);
                         $sql[] = "INSERT INTO `gcp_addresses` (`gid`, `gcid`, `type`, `country`," . " `postal`, `region`, `city`, `street`) VALUES ('{$group_id}', '{$id}', " . $address['type'] . "," . $address['country'] . ", " . $address['postal'] . ", " . $address['region'] . ", " . $address['city'] . ", " . $address['street'] . ");";
                     }
                 }
             }
             break;
         case 'ims':
             if (!empty($values)) {
                 foreach ($values as $im) {
                     if (!empty($im)) {
                         if (in_array(strtolower($im['protocol']), Kohana::config('contact.protocol'), TRUE)) {
                             $im['value'] = $this->db->escape($im['value']);
                             $im['type'] = $this->db->escape($im['type']);
                             $im['protocol'] = $this->db->escape($im['protocol']);
                             $sql[] = "INSERT INTO `gcp_ims` (`gid`, `gcid`, `protocol`, `type`, `value`)\n                            VALUES ('{$group_id}', '{$id}', {$im['protocol']}, {$im['type']}, {$im['value']});";
                         }
                     }
                 }
             }
             break;
         default:
             if (!empty($values)) {
                 foreach ($values as $value) {
                     if (!empty($value['value'])) {
                         $value['type'] = $this->db->escape($value['type']);
                         $value['value'] = $this->db->escape($value['value']);
                         $sql[] = "INSERT INTO `gcp_{$type}` (`gid`, `gcid`, `type`, `value`)\n                        VALUES ('{$group_id}', '{$id}', {$value['type']}, {$value['value']});";
                     }
                 }
             }
             break;
     }
     return $sql;
 }