示例#1
0
 /**
  * Tests that the sequences API works.
  */
 function testDbNextId()
 {
     $first = db_next_id();
     $second = db_next_id();
     // We can test for exact increase in here because we know there is no
     // other process operating on these tables -- normally we could only
     // expect $second > $first.
     $this->assertEqual($first + 1, $second, 'The second call from a sequence provides a number increased by one.');
     $result = db_next_id(1000);
     $this->assertEqual($result, 1001, 'Sequence provides a larger number than the existing ID.');
 }
示例#2
0
/**
 * Create a Drupal user and return Drupal ID
 * @param       email   email address of new user
 * @return      res     Drupal ID for new user or FALSE if error
 */
function civicrm_drupal_create_user($email, $rid = null)
{
    $email = trim($email);
    if (empty($email)) {
        return FALSE;
    }
    // If user already exists, return Drupal id
    $uid = db_result(db_query("SELECT uid FROM {users} WHERE mail = '%s'", $email));
    if ($uid) {
        return $uid;
    }
    // escape email to prevent sql injection
    $dao = new CRM_Core_DAO();
    $email = $dao->escape($email);
    // Default values for new user
    $params = array();
    $params['uid'] = db_next_id('{users}_uid');
    $params['name'] = $email;
    $params['pass'] = md5(uniqid(rand(), true));
    $params['mail'] = $email;
    $params['mode'] = 0;
    $params['access'] = 0;
    $params['status'] = 0;
    // don't allow user to login until verified
    $params['init'] = $email;
    $params['created'] = time();
    $db_fields = '(';
    $db_values = '(';
    foreach ($params as $key => $value) {
        $db_fields .= "{$key},";
        $db_values .= "'{$value}',";
    }
    $db_fields = rtrim($db_fields, ",");
    $db_values = rtrim($db_values, ",");
    $db_fields .= ')';
    $db_values .= ')';
    $q = "INSERT INTO {users} {$db_fields} VALUES {$db_values}";
    db_query($q);
    if ($rid) {
        // Delete any previous roles entry before adding the role id
        db_query('DELETE FROM {users_roles} WHERE uid = %d', $params['uid']);
        db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $params['uid'], $rid);
    }
    return $params['uid'];
}
示例#3
0
文件: admcol.php 项目: jacadym/picman
         $out .= trim($line) . "<BR>\n";
     }
     $frm[desc] = $out;
 }
 if ($page_id) {
     // Sprawdzanie tagów
     $tags = GetTags();
     $tagids = array();
     if (isset($frm['tags']) && count($frm['tags'])) {
         $tagids = $frm['tags'];
     }
     if (!empty($frm['newtags'])) {
         foreach (split(',', $frm['newtags']) as $_tag) {
             $tag = strtolower(trim($_tag));
             if (!in_array($tag, $tags)) {
                 $id = db_next_id('seq_tag');
                 db_query("INSERT INTO {tags} (id, name) VALUES (%d, '%s')", $id, $tag);
                 $tags[$id] = $tag;
                 array_push($tagids, $id);
             }
         }
     }
     db_query("DELETE FROM {tag_collections} WHERE id_col = %d", $page_id);
     if (count($tagids)) {
         db_query("INSERT INTO {tag_collections} (id_tag,id_col) SELECT id, %d FROM {tags} WHERE id IN (%s)", $page_id, join(',', $tagids));
     }
     $cat = db_fetch_array(db_query("SELECT uniqid FROM {categories} WHERE id = %d", $frm['parent']));
     $result = db_query("\n\t\t\tUPDATE {collections} SET\n\t\t\tuid_cat     = '%s',\n\t\t\tuniqid      = '%s',\n\t\t\tweight      = %d,\n\t\t\tdate_create = '%s',\n\t\t\tname        = '%s',\n\t\t\ttitle       = '%s',\n\t\t\theader      = '%s',\n\t\t\tdescription = '%s',\n\t\t\tstartnum    = %d,\n\t\t\tquantity    = %d,\n\t\t\tholes       = '%s',\n\t\t\tcoldir      = '%s',\n\t\t\tpicsubdir   = '%s',\n\t\t\tthumbsubdir = '%s',\n\t\t\tpictemp     = '%s',\n\t\t\tthumbtemp   = '%s',\n\t\t\tpgnumtemp   = '%s',\n\t\t\timgindex    = '%s',\n\t\t\ticoindex    = '%s',\n\t\t\trows        = %d,\n\t\t\tcols        = %d,\n\t\t\toptions     = '%s'\n\t\t\tWHERE id = %d", $cat['uniqid'], FrmDb($frm['uniqid']), $frm['position'], $frm['datecr'], FrmDb($frm['name']), FrmDb($frm['title']), FrmDb($frm['header']), FrmDb($frm['desc']), $frm['first'], $frm['quantity'], FrmDb($frm['holes']), FrmDb($frm['dirgr']), FrmDb($frm['dirimg']), FrmDb($frm['dirth']), FrmDb($frm['tempimg']), FrmDb($frm['tempth']), FrmDb($frm['temppage']), FrmDb($frm['introimg']), FrmDb($frm['thumbimg']), $frm['serrow'], $frm['sercol'], join('|', $arr_opt), $page_id);
     echo FramedTable1() . '<BR> &nbsp; OK! Modify Collection "' . $frm[name] . '" &nbsp; <BR><BR>' . FramedTable2();
 } else {
     // Tworzenie nowej grupy