Exemplo n.º 1
0
function try_to_unlock($attempt, $dir)
{
    /**
    * tries to ulock the page. if it does, the file holding the locked state is changed.
    * either way the result is sent back to the user.
    *
    * @since 1.0
    *
    * @caller ajax user action
    * @ingroup try to unlock
    *
    * @param string $attempt, string inputed by user
    * @param string $dir, the user's directory
    *
    * @return string $result, did the user enter the correct password
    *
    * @var string $password, the correct password
    * @var string $result, did the user enter the correct password
    */
    try {
        $dbLogin = db_login();
        $db = new PDO($dbLogin['dsn'], $dbLogin['user'], $dbLogin['pass']);
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $stmt = $db->prepare("SELECT * FROM projects WHERE directory='" . $dir . "' LIMIT 1");
        $stmt->execute();
        $row = $stmt->fetch();
        $password = $row['password'];
        $result = $attempt === $password ? 'yup' : 'nope';
        echo $result;
        if ($result === 'yup') {
            $sql = "UPDATE projects SET islocked=? WHERE directory=?";
            $query = $db->prepare($sql);
            $query->execute(array(0, $dir));
        }
    } catch (PDOException $e) {
        die('Could not connect to the database:<br/>' . $e);
    }
    die;
}
Exemplo n.º 2
0
<?php

//Log into the database
db_login();
/**
* Manageable - a light weight ORM for PHP
* by Andrew Drane - Andrew [at] andrewdrane [dot] com
* Contains finder and other object functions
* Creates objects based on Rows of the database
* Functions mimic Rails in some way - this is intended to make the management
*  of 1 to many attributes very easy. Page load times should be quick since
*  there isn't very much overhead. This is NOT intended to be as robust -
*  there's CAKE php for that and JOOMLA too. Just a stripped down ORM.
**/
class Manageable
{
    var $fields = array();
    var $table;
    var $has_many;
    var $belongs_to;
    //these are the values that should not be user modified
    var $auto_values = array("id", "created_at", "updated_at");
    //CONSTRUCTORS
    function Manageable()
    {
        $this->get_fields();
    }
    // Loads the $fields array for the object. This will contain all the
    // object's data propert names.
    function get_fields()
    {