Exemplo n.º 1
0
 /**
  * Add the Project to the database
  *
  * @return bool|string
  */
 public function post()
 {
     global $auth;
     $db = new dbConnection();
     if ($this->submission_id == '') {
         $this->submission_id = str_replace($this->name, ' ', '_');
     }
     $sub_id = $this->submission_id;
     if ($this->allowDownloadEdits) {
         $sub_id = sprintf('ec_ade::%s', $sub_id);
     }
     $res = $db->do_query("INSERT INTO project(name, submission_id, description, image, isPublic, isListed, publicSubmission, uploadToLocalServer, downloadFromLocalServer) VALUES ('{$this->name}', '{$sub_id}', '{$this->description}', '{$this->image}', " . ($this->isPublic ? "1" : "0") . ", " . ($this->isListed ? "1" : "0") . ", " . ($this->publicSubmission ? "1" : "0") . ", '{$this->uploadToLocalServer}', '{$this->downloadFromLocalServer}')");
     if ($res === true) {
         $this->fetch();
         foreach ($this->tables as $tbl) {
             $r = $tbl->addToDb();
             if ($r !== true) {
                 return $r;
             }
         }
         $qry = "INSERT INTO userprojectpermission (user, project, role) VALUES ({$auth->getEcUserId()}, {$this->id}, 3)";
         $res = $db->do_multi_query($qry);
         if (!$res === true) {
             die($res + " " + $qry);
         }
         return true;
     } else {
         return $res;
     }
 }
Exemplo n.º 2
0
function setupDB()
{
    global $cfg, $auth, $SITE_ROOT;
    try {
        $db = new dbConnection($_POST["un"], $_POST["pwd"]);
    } catch (Exception $e) {
        $_GET["redir"] = "pwd";
        siteTest();
        return;
    }
    if (!$db) {
        echo "DB not connected";
        return;
    }
    $sql = file_get_contents("./db/epicollect2.sql");
    $qrys = explode("~", $sql);
    for ($i = 0; $i < count($qrys); $i++) {
        if ($qrys[$i] != "") {
            $res = $db->do_multi_query($qrys[$i]);
            if ($res !== true && !preg_match("/already exists|Duplicate entry .* for key/", $res)) {
                siteHome();
                return;
            }
        }
    }
    flash('Please sign in to register as the first administartor of this server.');
    header(sprintf('location: http://%s%s/login.php', $_SERVER['HTTP_HOST'], $SITE_ROOT));
    return;
}