Example #1
0
 /**
  * Create new user
  * @access  public
  * @param   user_group_id: user group ID (1 [admin] or 2 [user])
  *          login: login name
  *          pwd: password
  *          email: email
  *          first_name: first name
  *          last_name: last name
  * @return  user id, if successful
  *          false and add error into global var $msg, if unsuccessful
  * @author  Cindy Qi Li
  */
 public function Create($user_group_id, $login, $pwd, $email, $first_name, $last_name, $is_author, $organization, $phone, $address, $city, $province, $country, $postal_code, $status)
 {
     global $addslashes;
     /* email check */
     $login = $addslashes(strtolower(trim($login)));
     $email = $addslashes(trim($email));
     $first_name = $addslashes(str_replace('<', '', trim($first_name)));
     $last_name = $addslashes(str_replace('<', '', trim($last_name)));
     $organization = $addslashes(trim($organization));
     $phone = $addslashes(trim($phone));
     $address = $addslashes(trim($address));
     $city = $addslashes(trim($city));
     $province = $addslashes(trim($province));
     $country = $addslashes(trim($country));
     $postal_code = $addslashes(trim($postal_code));
     if ($this->isFieldsValid('new', $user_group_id, $login, $email, $first_name, $last_name, $is_author, $organization, $phone, $address, $city, $province, $country, $postal_code)) {
         if ($status == "") {
             if (defined('TR_EMAIL_CONFIRMATION') && TR_EMAIL_CONFIRMATION) {
                 $status = TR_STATUS_UNCONFIRMED;
             } else {
                 $status = TR_STATUS_ENABLED;
             }
         }
         /* insert into the db */
         $sql = "INSERT INTO " . TABLE_PREFIX . "users\n\t\t\t              (login,\n\t\t\t               password,\n\t\t\t               user_group_id,\n\t\t\t               first_name,\n\t\t\t               last_name,\n\t\t\t               email,\n\t\t\t               is_author,\n\t\t\t               organization,\n\t\t\t               phone,\n\t\t\t               address,\n\t\t\t               city,\n\t\t\t               province,\n\t\t\t               country,\n\t\t\t               postal_code,\n\t\t\t               web_service_id,\n\t\t\t               status,\n\t\t\t               create_date\n\t\t\t               )\n\t\t\t       VALUES ('" . $login . "',\n\t\t\t               '" . $pwd . "',\n\t\t\t               " . $user_group_id . ",\n\t\t\t               '" . $first_name . "',\n\t\t\t               '" . $last_name . "', \n\t\t\t               '" . $email . "',\n\t\t\t               " . $is_author . ",\n\t\t\t               '" . $organization . "',\n\t\t\t               '" . $phone . "',\n\t\t\t               '" . $address . "',\n\t\t\t               '" . $city . "',\n\t\t\t               '" . $province . "',\n\t\t\t               '" . $country . "',\n\t\t\t               '" . $postal_code . "',\n\t\t\t               '" . Utility::getRandomStr(32) . "',\n\t\t\t               " . $status . ", \n\t\t\t               now())";
         if (!$this->execute($sql)) {
             $msg->addError('DB_NOT_UPDATED');
             return false;
         } else {
             return mysql_insert_id();
         }
     } else {
         return false;
     }
 }
 /**
  * Create a new consumer record
  * @access  public
  * @param   consumer
  * @return  consumer id, if successful
  *          false and add error into global var $msg, if unsuccessful
  * @author  Cindy Qi Li
  */
 public function Create($consumer, $expire_threshold)
 {
     global $addslashes, $msg;
     $missing_fields = array();
     /* email check */
     $consumer = $addslashes(trim($consumer));
     /* login name check */
     if ($consumer == '') {
         $missing_fields[] = _AT('consumer');
     }
     if ($missing_fields) {
         $missing_fields = implode(', ', $missing_fields);
         $msg->addError(array('EMPTY_FIELDS', $missing_fields));
     }
     if (!$msg->containsErrors()) {
         /* insert into the db */
         $consumer_key = Utility::getRandomStr(16);
         $consumer_secret = Utility::getRandomStr(16);
         $sql = "INSERT INTO " . TABLE_PREFIX . "oauth_server_consumers\n\t\t\t              (consumer,\n\t\t\t               consumer_key,\n\t\t\t               consumer_secret,\n\t\t\t               expire_threshold,\n\t\t\t               create_date\n\t\t\t               )\n\t\t\t       VALUES ('" . $consumer . "',\n\t\t\t               '" . $consumer_key . "',\n\t\t\t               '" . $consumer_secret . "',\n\t\t\t               " . $expire_threshold . ",\n\t\t\t               now()\n\t\t\t              )";
         if (!$this->execute($sql)) {
             $msg->addError('DB_NOT_UPDATED');
             return false;
         } else {
             return mysql_insert_id();
         }
     } else {
         return false;
     }
 }
Example #3
0
    if (isset($_GET['tile'])) {
        header('Location: ' . $_base_path . 'tools/tile/index.php');
    } else {
        header('Location: ../index.php');
    }
    exit;
}
/* check if ../content/import/ exists */
$import_path = TR_TEMP_DIR . 'import/';
$content_path = TR_TEMP_DIR;
if (!is_dir($import_path)) {
    if (!@mkdir($import_path, 0700)) {
        $msg->addError('IMPORTDIR_FAILED');
    }
}
$import_path .= Utility::getRandomStr(16) . '/';
if (is_dir($import_path)) {
    clr_dir($import_path);
}
if (!@mkdir($import_path, 0700)) {
    $msg->addError('IMPORTDIR_FAILED');
}
if ($msg->containsErrors()) {
    if (isset($_GET['tile'])) {
        header('Location: ' . $_base_path . 'tools/tile/index.php');
    } else {
        header('Location: ../index.php');
    }
    exit;
}
/* extract the entire archive into TR_COURSE_CONTENT . import/$course using the call back function to filter out php files */
 function new_access_token($token, $consumer)
 {
     /*{{{*/
     $access_token_key = Utility::getRandomStr(18);
     $access_token_secret = Utility::getRandomStr(18);
     $request_token_row = $this->oauthServerTokensDAO->getByTokenAndType($token, 'request');
     $this->oauthServerTokensDAO->Create($request_token_row[0]['consumer_id'], $access_token_key, 'access', $access_token_secret, $request_token_row[0]['user_id']);
     $this->oauthServerTokensDAO->deleteByTokenAndType($token, 'request');
     $access_token = new OAuthToken($access_token_key, $access_token_secret);
     return $access_token;
 }