Exemplo n.º 1
0
 /**
  * This is the name of the file that will get downloaded
  *
  * @return string
  */
 public function getCleanName()
 {
     $ext = '.elabftw.zip';
     if (count($this->idArr) === 1) {
         return $this->zipped['date'] . "-" . $this->cleanTitle . $ext;
     }
     return kdate() . $ext;
 }
Exemplo n.º 2
0
 /**
  * Do the work
  *
  */
 private function readCsv()
 {
     $row = 0;
     $column = array();
     // loop the lines
     while ($data = fgetcsv($this->handle, 0, ",")) {
         $num = count($data);
         // get the column names (first line)
         if ($row == 0) {
             for ($i = 0; $i < $num; $i++) {
                 $column[] = $data[$i];
             }
             $row++;
             continue;
         }
         $row++;
         $title = $data[0];
         $body = '';
         $j = 0;
         foreach ($data as $line) {
             $body .= "<p><strong>" . $column[$j] . " :</strong> " . $line . '</p>';
             $j++;
         }
         // clean the body
         $body = str_replace('<p><strong> :</strong> </p>', '', $body);
         // SQL for importing
         $sql = "INSERT INTO items(team, title, date, body, userid, type)\n                VALUES(:team, :title, :date, :body, :userid, :type)";
         $req = $this->pdo->prepare($sql);
         $result = $req->execute(array('team' => $_SESSION['team_id'], 'title' => $title, 'date' => kdate(), 'body' => $body, 'userid' => $_SESSION['userid'], 'type' => $this->itemType));
         if ($result) {
             $this->inserted++;
         } else {
             throw new Exception('Error in SQL query!');
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Duplicate an item.
  *
  * @param int $id The id of the item to duplicate
  * @return int $newId The id of the newly created item
  */
 public function duplicateItem($id)
 {
     // SQL to get data from the item we duplicate
     $sql = "SELECT * FROM items WHERE id = :id AND team = :team";
     $req = $this->pdo->prepare($sql);
     $req->bindParam(':id', $id);
     $req->bindParam(':team', $_SESSION['team_id']);
     $req->execute();
     $items = $req->fetch();
     // SQL for duplicateItem
     $sql = "INSERT INTO items(team, title, date, body, userid, type) VALUES(:team, :title, :date, :body, :userid, :type)";
     $req = $this->pdo->prepare($sql);
     $req->execute(array('team' => $items['team'], 'title' => $items['title'], 'date' => kdate(), 'body' => $items['body'], 'userid' => $_SESSION['userid'], 'type' => $items['type']));
     $newId = $this->pdo->lastInsertId();
     self::copyTags($id, $newId, 'item');
     return $newId;
 }
Exemplo n.º 4
0
<div class="span10">
	<article>
		<h1><?php 
echo $topic->title;
?>
</h1>
		<div>
			<div><?php 
echo kdate($topic->created);
?>
</div>
			<?php 
echo auto_link($topic->description);
?>
		</div>
	</article>
<div>     
    <form action="/index.php/topic/delete" method="post">
        <input type="hidden" name="topic_id" value="<?php 
echo $topic->id;
?>
" />
        <a href="/index.php/topic/add" class="btn">추가</a>       
        <input type="submit" class="btn" value="삭제" />
    </form>
</div>
</div>
Exemplo n.º 5
0
    }
    // SQL for create experiments
    $sql = "INSERT INTO experiments(team, title, date, body, status, elabid, visibility, userid) VALUES(:team, :title, :date, :body, :status, :elabid, :visibility, :userid)";
    $req = $pdo->prepare($sql);
    $result = $req->execute(array('team' => $_SESSION['team_id'], 'title' => $title, 'date' => kdate(), 'body' => $body, 'status' => $status, 'elabid' => $elabid, 'visibility' => 'team', 'userid' => $_SESSION['userid']));
} else {
    // create item for DB
    // SQL to get template
    $sql = "SELECT template FROM items_types WHERE id = :id";
    $get_tpl = $pdo->prepare($sql);
    $get_tpl->execute(array('id' => $type));
    $get_tpl_body = $get_tpl->fetch();
    // SQL for create DB item
    $sql = "INSERT INTO items(team, title, date, body, userid, type) VALUES(:team, :title, :date, :body, :userid, :type)";
    $req = $pdo->prepare($sql);
    $result = $req->execute(array('team' => $_SESSION['team_id'], 'title' => 'Untitled', 'date' => kdate(), 'body' => $get_tpl_body['template'], 'userid' => $_SESSION['userid'], 'type' => $type));
}
// Check if insertion is successful and redirect to the newly created experiment in edit mode
if ($result) {
    // info box
    $msg_arr[] = _('New item created successfully.');
    $_SESSION['infos'] = $msg_arr;
    if ($type === 'experiments') {
        header('location: ../experiments.php?mode=edit&id=' . $pdo->lastInsertId() . '');
        exit;
    } else {
        header('location: ../database.php?mode=edit&id=' . $pdo->lastInsertId() . '');
        exit;
    }
} else {
    die;
Exemplo n.º 6
0
/**
 * Check if the date is valid.
 *
 * @param int $input The date to check
 * @return integer|string $input The input date if it's valid, or the date of today if not
 */
function check_date($input)
{
    // Check DATE (is != null ? is 8 in length ? is int ? is valable ?)
    if (isset($input) && !empty($input) && strlen($input) == '8' && is_pos_int($input)) {
        // Check if day/month are good
        $datemonth = substr($input, 4, 2);
        $dateday = substr($input, 6, 2);
        if ($datemonth <= '12' && $dateday <= '31' && $datemonth > '0' && $dateday > '0') {
            // SUCCESS on every test
            return $input;
        }
    }
    return kdate();
}
Exemplo n.º 7
0
            continue;
        }
        $row++;
        $title = $data[0];
        $body = '';
        $j = 0;
        foreach ($data as $line) {
            $body .= "<p><strong>" . $column[$j] . " :</strong> " . $line . '</p>';
            $j++;
        }
        // clean the body
        $body = str_replace('<p><strong> :</strong> </p>', '', $body);
        // SQL for importing
        $sql = "INSERT INTO items(team, title, date, body, userid, type) VALUES(:team, :title, :date, :body, :userid, :type)";
        $req = $pdo->prepare($sql);
        $result = $req->execute(array('team' => $_SESSION['team_id'], 'title' => $title, 'date' => kdate(), 'body' => $body, 'userid' => $_SESSION['userid'], 'type' => $type));
        if ($result) {
            $inserted++;
        }
    }
    fclose($handle);
    $msg_arr[] = $inserted . ' ' . _('items were imported successfully.');
    $_SESSION['infos'] = $msg_arr;
}
// END CODE TO IMPORT CSV
?>

<script>
// used on import csv to go to next step
function goNext(x) {
    if(x == '') {
Exemplo n.º 8
0
/**
 * Duplicate an item.
 *
 * @param int $id The id of the item to duplicate
 * @param string $type Can be 'experiments' or 'item'
 * @return int Will return the ID of the new item or 0 if error
 */
function duplicate_item($id, $type)
{
    global $pdo;
    $result = false;
    $result_tags = false;
    if ($type === 'experiments') {
        $elabid = generate_elabid();
        // what will be the status ?
        // go pick what is the default status upon creating experiment
        // there should be only one because upon making a status default,
        // all the others are made not default
        $sql = 'SELECT id FROM status WHERE is_default = true AND team = :team LIMIT 1';
        $req = $pdo->prepare($sql);
        $req->bindParam(':team', $_SESSION['team_id']);
        $req->execute();
        $status = $req->fetchColumn();
        // if there is no is_default status
        // we take the first status that come
        if (!$status) {
            $sql = 'SELECT id FROM status WHERE team = :team LIMIT 1';
            $req = $pdo->prepare($sql);
            $req->bindParam(':team', $_SESSION['team_id']);
            $req->execute();
            $status = $req->fetchColumn();
        }
        // SQL to get data from the experiment we duplicate
        $sql = "SELECT title, body, visibility FROM experiments WHERE id = " . $id;
        $req = $pdo->prepare($sql);
        $req->execute();
        $data = $req->fetch();
        // let's add something at the end of the title to show it's a duplicate
        // capital i looks good enough
        $title = $data['title'] . ' I';
        // SQL for duplicateXP
        $sql = "INSERT INTO experiments(team, title, date, body, status, elabid, visibility, userid) VALUES(:team, :title, :date, :body, :status, :elabid, :visibility, :userid)";
        $req = $pdo->prepare($sql);
        $result = $req->execute(array('team' => $_SESSION['team_id'], 'title' => $title, 'date' => kdate(), 'body' => $data['body'], 'status' => $status, 'elabid' => $elabid, 'visibility' => $data['visibility'], 'userid' => $_SESSION['userid']));
        // END SQL main
    }
    if ($type === 'items') {
        // SQL to get data from the item we duplicate
        $sql = "SELECT * FROM items WHERE id = " . $id;
        $req = $pdo->prepare($sql);
        $req->execute();
        $data = $req->fetch();
        // SQL for duplicateDB
        $sql = "INSERT INTO items(team, title, date, body, userid, type) VALUES(:team, :title, :date, :body, :userid, :type)";
        $req = $pdo->prepare($sql);
        $result = $req->execute(array('team' => $data['team'], 'title' => $data['title'], 'date' => kdate(), 'body' => $data['body'], 'userid' => $_SESSION['userid'], 'type' => $data['type']));
        // END SQL main
    }
    // Get what is the id we just created
    $newid = $pdo->lastInsertId();
    if ($type === 'experiments') {
        // TAGS
        $sql = "SELECT tag FROM experiments_tags WHERE item_id = :id";
        $req = $pdo->prepare($sql);
        $req->execute(array('id' => $id));
        $tag_number = $req->rowCount();
        if ($tag_number > 0) {
            while ($tags = $req->fetch()) {
                // Put them in the new one. here $newid is the new exp created
                $sql = "INSERT INTO experiments_tags(tag, item_id, userid) VALUES(:tag, :item_id, :userid)";
                $reqtag = $pdo->prepare($sql);
                $result_tags = $reqtag->execute(array('tag' => $tags['tag'], 'item_id' => $newid, 'userid' => $_SESSION['userid']));
            }
        } else {
            //no tag
            $result_tags = true;
        }
        // LINKS
        $linksql = "SELECT link_id FROM experiments_links WHERE item_id = :id";
        $linkreq = $pdo->prepare($linksql);
        $result_links = $linkreq->execute(array('id' => $id));
        while ($links = $linkreq->fetch()) {
            $sql = "INSERT INTO experiments_links (link_id, item_id) VALUES(:link_id, :item_id)";
            $req = $pdo->prepare($sql);
            $result_links = $req->execute(array('link_id' => $links['link_id'], 'item_id' => $newid));
        }
        if ($result && $result_tags && $result_links) {
            return $newid;
        }
        return 0;
    } else {
        // DB
        // TAGS
        $sql = "SELECT tag FROM items_tags WHERE item_id = " . $id;
        $req = $pdo->prepare($sql);
        $req->execute();
        $tag_number = $req->rowCount();
        // we initilize $result_tags here in case there is now tag to duplicate
        $result_tags = true;
        if ($tag_number > 0) {
            while ($tags = $req->fetch()) {
                // Put them in the new one. here $newid is the new exp created
                $sql = "INSERT INTO items_tags(tag, item_id) VALUES(:tag, :item_id)";
                $reqtag = $pdo->prepare($sql);
                $result_tags = $reqtag->execute(array('tag' => $tags['tag'], 'item_id' => $newid));
            }
        }
        if ($result && $result_tags) {
            return $newid;
        }
        return false;
    }
}
Exemplo n.º 9
0
$errflag = false;
// CHECKS
// ID
if (is_pos_int($_POST['item_id'])) {
    $id = $_POST['item_id'];
    if (!item_is_in_team($id, $_SESSION['team_id'])) {
        die(_('This section is out of your reach.'));
    }
} else {
    $id = '';
    $msg_arr[] = _("The id parameter is not valid!");
    $errflag = true;
}
$title = check_title($_POST['title']);
// the date gets updated to today's date
$date = kdate();
$body = check_body($_POST['body']);
// Store stuff in Session to get it back if error input
$_SESSION['new_title'] = $title;
$_SESSION['new_date'] = $date;
// If input errors, redirect back to the edit form
if ($errflag) {
    $_SESSION['errors'] = $msg_arr;
    session_write_close();
    header("location: ../database.php?mode=edit&id=" . $id);
    exit;
}
// SQL for editDB
$sql = "UPDATE items \n        SET title = :title, \n        date = :date, \n        body = :body, \n        userid = :userid \n        WHERE id = :id";
$req = $pdo->prepare($sql);
$result = $req->execute(array('title' => $title, 'date' => $date, 'body' => $body, 'userid' => $_SESSION['userid'], 'id' => $id));
Exemplo n.º 10
0
// Switch exp/items just for the table to search in sql requests
if ($_GET['type'] === 'experiments') {
    $table = 'experiments';
} elseif ($_GET['type'] === 'items') {
    $table = 'items';
} else {
    die(_("The type parameter is not valid."));
}
// CREATE URL
$url = 'https://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['PHP_SELF'];
// Check id is valid and assign it to $id
if (isset($_GET['id']) && !empty($_GET['id'])) {
    $id_arr = explode(" ", $_GET['id']);
    // BEGIN ZIP
    // name of the downloadable file
    $zipname = kdate() . ".export.elabftw";
    $zipfile = 'uploads/export/' . $zipname . "-" . hash("sha512", uniqid(rand(), true)) . ".zip";
    $zip = new ZipArchive();
    $res = $zip->open($zipfile, ZipArchive::CREATE);
    if ($res === true) {
        foreach ($id_arr as $id) {
            // MAIN LOOP
            ////////////////
            // SQL to get info on the item we are zipping
            if ($table == 'experiments') {
                $sql = "SELECT * FROM experiments WHERE id = :id LIMIT 1";
            } else {
                $sql = "SELECT items.*,\n                    items_types.name AS items_typesname\n                    FROM items\n                    LEFT JOIN items_types ON (items.type = items_types.id)\n                    WHERE items.id = :id LIMIT 1";
            }
            $req = $pdo->prepare($sql);
            $req->bindParam(':id', $id, PDO::PARAM_INT);
Exemplo n.º 11
0
<?php

error_reporting(0);
print "Author: mOon Blog:www.moonhack.org Bbs:www.90sec.org Data:2012.8.27\r\n";
print "查询出现异常请更换IP 如有问题联系 邮箱 moonlxmoon@gamil.com\r\n";
$a = file('url.txt');
foreach ($a as $_key => $_value) {
    $_value = trim($_value);
    $_value2 = qz($_value);
    pr($_value);
    if ($is_true) {
        w($_value, $_value2, pr($_value), url_1($_value), url_2($_value), kdate($_value));
    }
}
function url_1($_value)
{
    $url = "http://www.baidu.com/s?wd=site%3A{$_value}";
    $url = file_get_contents($url);
    $patth = '/class="site_tip"><strong>(.*?)<\\/strong>/';
    if (preg_match($patth, $url, $data)) {
        if (preg_match('/[\\d|,]+/', $data[1], $a)) {
            return $a[0];
        }
    }
}
function url_2($_value)
{
    $url = "http://www.baidu.com/s?wd=domain%3A{$_value}";
    $url = file_get_contents($url);
    $patth = '/style="margin-left:120px" >(.+?)<\\/span>/';
    if (preg_match($patth, $url, $data)) {
Exemplo n.º 12
0
function duplicate_item($id, $type)
{
    global $bdd;
    if ($type === 'experiments') {
        $elabid = generate_elabid();
        // SQL to get latest revision from the experiment we duplicate
        $sql = "SELECT rev.rev_id, rev.rev_title, rev.rev_body, exp.visibility FROM revisions as rev JOIN experiments as exp ON rev.experiment_id = exp.id WHERE exp.id = :id";
        $req = $bdd->prepare($sql);
        $req->execute(array('id' => $id));
        $data = $req->fetch();
        //now get content of latest revision and
        // SQL for duplicateXP
        $sql = "INSERT INTO experiments(date, status, elabid, visibility, userid_creator) VALUES(:date, :status, :elabid, :visibility, :userid)";
        $req = $bdd->prepare($sql);
        $result = $req->execute(array('date' => kdate(), 'status' => 'running', 'elabid' => $elabid, 'visibility' => $data['visibility'], 'userid' => $_SESSION['userid']));
        // END SQL main
        // Get what is the experiment id we just created
        // Get what is the experiment id we just created
        $sql = "SELECT LAST_INSERT_ID();";
        $req = $bdd->prepare($sql);
        $req->execute();
        $data1 = $req->fetch();
        $newid = $data1['LAST_INSERT_ID()'];
        // now copy the text for the new page into the revisions table
        $sql = "INSERT INTO revisions(user_id, experiment_id, rev_notes, rev_body, rev_title) VALUES(:userid, :expid, :notes, :body, :title)";
        $req = $bdd->prepare($sql);
        $result = $req->execute(array('title' => $data['rev_title'], 'expid' => $newid, 'notes' => "Duplication of experiment {$id}.", 'body' => $data['rev_body'], 'userid' => $_SESSION['userid']));
        // now populate rev-id for expt
        $sql = "UPDATE experiments SET rev_id=LAST_INSERT_ID() WHERE id = " . $newid;
        $req = $bdd->prepare($sql);
        $result = $req->execute();
    }
    if ($type === 'items') {
        // SQL to get data from the item we duplicate
        $sql = "SELECT * FROM items WHERE id = :id";
        $req = $bdd->prepare($sql);
        $req->execute(array('id' => $id));
        $data = $req->fetch();
        // SQL for duplicateDB
        $sql = "INSERT INTO items(title, date, body, userid, type) VALUES(:title, :date, :body, :userid, :type)";
        $req = $bdd->prepare($sql);
        $result = $req->execute(array('title' => $data['title'], 'date' => kdate(), 'body' => $data['body'], 'userid' => $_SESSION['userid'], 'type' => $data['type']));
        // END SQL main
        // Get what is the item id we just created
        $sql = "SELECT LAST_INSERT_ID();";
        $req = $bdd->prepare($sql);
        $req->execute();
        $data1 = $req->fetch();
        $newid = $data1['LAST_INSERT_ID()'];
    }
    if ($type === 'experiments') {
        // TAGS
        $sql = "SELECT tag FROM experiments_tags WHERE item_id = :id";
        $req = $bdd->prepare($sql);
        $req->execute(array('id' => $id));
        $tag_number = $req->rowCount();
        if ($tag_number > 1) {
            while ($tags = $req->fetch()) {
                // Put them in the new one. here $newid is the new exp created
                $sql = "INSERT INTO experiments_tags(tag, item_id, userid) VALUES(:tag, :item_id, :userid)";
                $reqtag = $bdd->prepare($sql);
                $result_tags = $reqtag->execute(array('tag' => $tags['tag'], 'item_id' => $newid, 'userid' => $_SESSION['userid']));
            }
        } else {
            //no tag
            $result_tags = true;
        }
        // LINKS
        $linksql = "SELECT link_id FROM experiments_links WHERE item_id = :id";
        $linkreq = $bdd->prepare($linksql);
        $result_links = $linkreq->execute(array('id' => $id));
        while ($links = $linkreq->fetch()) {
            $sql = "INSERT INTO experiments_links (link_id, item_id) VALUES(:link_id, :item_id)";
            $req = $bdd->prepare($sql);
            $result_links = $req->execute(array('link_id' => $links['link_id'], 'item_id' => $newid));
        }
        if ($result && $result_tags && $result_links) {
            return $newid;
        }
        return false;
    } else {
        // DB
        // TAGS
        $sql = "SELECT tag FROM items_tags WHERE item_id = :id";
        $req = $bdd->prepare($sql);
        $req->execute(array('id' => $id));
        while ($tags = $req->fetch()) {
            // Put them in the new one. here $newid is the new exp created
            $sql = "INSERT INTO items_tags(tag, item_id) VALUES(:tag, :item_id)";
            $reqtag = $bdd->prepare($sql);
            $result_tags = $reqtag->execute(array('tag' => $tags['tag'], 'item_id' => $newid));
        }
        if ($result && $result_tags) {
            return $newid;
        }
        return false;
    }
}