Esempio n. 1
0
 /**
  * Gets an array of Tags from the database, or NULL on failure.
  * @param TagSearchParameters $SearchParameters
  * @param string $OrderClause
  * @param string $LimitClause
  * @return array(Tag) | NULL
  */
 public static function GetTags($SearchParameters = NULL, $OrderClause = 'tag_name ASC', $LimitClause = NULL)
 {
     global $dbi;
     $SearchParameters = $SearchParameters ? $SearchParameters : new TagSearchParameters();
     $OrderClause = empty($OrderClause) ? 'tag_name ASC' : $OrderClause;
     $q = sprintf("\n\t\t\tSELECT\n\t\t\t\t`tag_id`, `tag_name`\n\t\t\tFROM\n\t\t\t\t`Tag`\n\t\t\tWHERE\n\t\t\t\tmut_deleted = -1\n\t\t\t\t%1\$s\n\t\t\tORDER BY\n\t\t\t\t%2\$s\n\t\t\t%3\$s", $SearchParameters->getWhere(), $OrderClause, $LimitClause ? ' LIMIT ' . $LimitClause : NULL);
     if (!($stmt = $dbi->prepare($q))) {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
     DBi::BindParamsToSelect($SearchParameters, $stmt);
     if ($stmt->execute()) {
         $OutArray = array();
         $stmt->bind_result($tag_id, $tag_name);
         while ($stmt->fetch()) {
             $o = new self($tag_id, $tag_name);
             $OutArray[] = $o;
         }
         $stmt->close();
         return $OutArray;
     } else {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
 }
Esempio n. 2
0
function connectI()
{
    $dbi = mysqli_connect('localhost', 'swanso52', 'utagydbo4');
    // $dbi = mysqli_connect('localhost', 'root', 'utagydbo');
    DBi::$link = $dbi;
    if (mysqli_connect_errno()) {
        die("Could not connect to database: mysqli_connect()");
    }
    return $dbi;
}
Esempio n. 3
0
 public function buildWhere(&$isWhereString, &$whereBindParams, &$where)
 {
     //$isWhereString
     //$where
     $whereString = '';
     if ($isWhereString) {
         $whereString .= 'WHERE';
         $whereParamTypes =& $whereBindParams[0];
         //first param passed to bind_param('ssii', ..)
         $i = 0;
         foreach ($where as $k => $item) {
             //	SERVER::dump($item);
             $fieldName = '';
             //append fieldtype (s,i...) to first element of array
             $whereParamTypes .= DBi::SplitField($item['field'], $fieldName);
             //'s:username' return and remove type from field
             //-------------------------------------------
             //allow arrays of values to be passed
             if (is_array($where[$k]['value']) and false) {
                 //needs more testing
                 $where[$k]['value'] = join(', ', $where[$k]['value']);
                 $operator = 'IN';
                 $opTemplate = '(?)';
             } else {
                 $operator = isset($item['operator']) ? $item['operator'] : '=';
                 $opTemplate = '?';
             }
             //-------------------------------------------
             //append field to bind array
             $whereBindParams[] =& $where[$k]['value'];
             $condition = $i == 0 ? '' : ' ' . $item['condition'];
             // first condition following WHERE not needed
             $whereString .= $condition . ' ' . $fieldName . ' ' . $operator . ' ' . $opTemplate;
             $i++;
         }
     }
     return $whereString;
 }
Esempio n. 4
0
 /**
  * Gets an array of Videos from the database, or NULL on failure.
  * @param VideoSearchParameters $SearchParameters
  * @param string $OrderClause
  * @param string $LimitClause
  * @return Array(Video) | NULL
  */
 public static function GetVideos($SearchParameters = NULL, $OrderClause = 'model_firstname ASC, model_lastname ASC, set_prefix ASC, set_name ASC, video_filename ASC', $LimitClause = NULL)
 {
     global $dbi;
     $SearchParameters = $SearchParameters ? $SearchParameters : new VideoSearchParameters();
     $OrderClause = empty($OrderClause) ? 'model_firstname ASC, model_lastname ASC, set_prefix ASC, set_name ASC, video_filename ASC' : $OrderClause;
     $q = sprintf("\n\t\t\tSELECT\n\t\t\t\t`video_id`, `video_filename`, `video_fileextension`, `video_filesize`, `video_filechecksum`, `video_filecrc32`, \n\t\t\t\t`set_id`, `set_prefix`, `set_name`, `set_containswhat`,\n\t\t\t\t`model_id`, `model_firstname`, `model_lastname`\n\t\t\tFROM\n\t\t\t\t`vw_Video`\n\t\t\tWHERE\n\t\t\t\tmut_deleted = -1\n\t\t\t\t%1\$s\n\t\t\tORDER BY\n\t\t\t\t%2\$s\n\t\t\t%3\$s", $SearchParameters->getWhere(), $OrderClause, $LimitClause ? ' LIMIT ' . $LimitClause : NULL);
     if (!($stmt = $dbi->prepare($q))) {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
     DBi::BindParamsToSelect($SearchParameters, $stmt);
     if ($stmt->execute()) {
         $OutArray = array();
         $stmt->bind_result($video_id, $video_filename, $video_fileextension, $video_filesize, $video_filechecksum, $video_filecrc32, $set_id, $set_prefix, $set_name, $set_containswhat, $model_id, $model_firstname, $model_lastname);
         while ($stmt->fetch()) {
             $o = new self($video_id, $video_filename, $video_fileextension, $video_filesize, $video_filechecksum, $video_filecrc32, $set_id, $set_prefix, $set_name, $set_containswhat, $model_id, $model_firstname, $model_lastname);
             $OutArray[] = $o;
         }
         $stmt->close();
         return $OutArray;
     } else {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
 }
Esempio n. 5
0
 /**
  * Gets an array of CacheImages from the database, or NULL on failure.
  * @param $SearchParameters $SearchParameters
  * @param string $OrderClause
  * @param string $LimitClause
  */
 public static function GetCacheImages($SearchParameters = NULL, $OrderClause = NULL, $LimitClause = NULL)
 {
     global $dbi;
     $SearchParameters = $SearchParameters ? $SearchParameters : new CacheImageSearchParameters();
     $OrderClause = empty($OrderClause) ? 'index_id ASC, model_id ASC, set_id ASC, image_id ASC, video_id ASC' : $OrderClause;
     $q = sprintf("\n\t\t\tSELECT\n\t\t\t\t`cache_id`, `index_id`, `model_id`, `set_id`, `image_id`, `video_id`, `cache_imagewidth`, `cache_imageheight`, `index_sequence_number`, `index_sequence_total`\n\t\t\tFROM\n\t\t\t\t`CacheImage`\n\t\t\tWHERE\n\t\t\t\t1 = 1\n\t\t\t\t%1\$s\n\t\t\tORDER BY\n\t\t\t\t%2\$s\n\t\t\t%3\$s", $SearchParameters->getWhere(), $OrderClause, $LimitClause ? ' LIMIT ' . $LimitClause : NULL);
     if (!($stmt = $dbi->prepare($q))) {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
     DBi::BindParamsToSelect($SearchParameters, $stmt);
     if ($stmt->execute()) {
         $OutArray = array();
         $stmt->bind_result($cache_id, $index_id, $model_id, $set_id, $image_id, $video_id, $cache_imagewidth, $cache_imageheight, $index_sequence_number, $index_sequence_total);
         while ($stmt->fetch()) {
             $o = new self($cache_id, $index_id, $model_id, $set_id, $image_id, $video_id, $cache_imagewidth, $cache_imageheight, $index_sequence_number, $index_sequence_total);
             $OutArray[] = $o;
         }
         $stmt->close();
         return $OutArray;
     } else {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
 }
Esempio n. 6
0
<?php

require "connect_db_settings.php";
/*define('DB_SERVER', getenv('OPENSHIFT_MYSQL_DB_HOST'));
define('DB_NAME',getenv('OPENSHIFT_GEAR_NAME'));
define('DB_USER',getenv('OPENSHIFT_MYSQL_DB_USERNAME'));
define('DB_PASSWORD',getenv('OPENSHIFT_MYSQL_DB_PASSWORD'));*/
class DBi
{
    public static $conn;
    public static function mysqli_result($res, $row = 0, $col = 0)
    {
        $numrows = mysqli_num_rows($res);
        if ($numrows && $row <= $numrows - 1 && $row >= 0) {
            mysqli_data_seek($res, $row);
            $resrow = is_numeric($col) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
            if (isset($resrow[$col])) {
                return $resrow[$col];
            }
        }
        return false;
    }
}
DBi::$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
Esempio n. 7
0
 /**
  * Gets Tag2All records from the database or NULL on failure.
  * @param Tag2AllSearchParameters $SearchParameters
  * @param string $OrderClause
  * @return array(Tag2All) | NULL
  */
 public static function GetTag2Alls($SearchParameters = NULL, $OrderClause = 'tag_name ASC')
 {
     global $dbi;
     $SearchParameters = $SearchParameters ? $SearchParameters : new Tag2AllSearchParameters();
     $OrderClause = empty($OrderClause) ? 'tag_name ASC' : $OrderClause;
     $q = sprintf("\n\t\t\tSELECT\n\t\t\t\t`tag_id`, `tag_name`, `model_id`, `set_id`, `image_id`, `video_id`\n\t\t\tFROM\n\t\t\t\t`vw_Tag2All`\n\t\t\tWHERE\n\t\t\t\t1 = 1\n\t\t\t\t%1\$s\n\t\t\tORDER BY\n\t\t\t\t%2\$s", $SearchParameters->getWhere(), $OrderClause);
     if (!($stmt = $dbi->prepare($q))) {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
     DBi::BindParamsToSelect($SearchParameters, $stmt);
     if ($stmt->execute()) {
         $OutArray = array();
         $stmt->bind_result($tag_id, $tag_name, $model_id, $set_id, $image_id, $video_id);
         while ($stmt->fetch()) {
             $o = new self($tag_id, $tag_name, $model_id, $set_id, $image_id, $video_id);
             $OutArray[] = $o;
         }
         $stmt->close();
         return $OutArray;
     } else {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
 }
Esempio n. 8
0
 /**
  * Gets an array of Models from the database, or NULL on failure.
  * @param ModelSearchParameters $SearchParameters
  * @param string $OrderClause
  * @param string $LimitClause
  * @return array(Model)
  */
 public static function GetModels($SearchParameters = NULL, $OrderClause = 'model_firstname ASC, model_lastname ASC', $LimitClause = NULL)
 {
     global $dbi;
     $SearchParameters = $SearchParameters ? $SearchParameters : new ModelSearchParameters();
     $OrderClause = empty($OrderClause) ? 'model_firstname ASC, model_lastname ASC' : $OrderClause;
     $q = sprintf("\n\t\t\t\tSELECT\n\t\t\t\t\t`model_id`,`model_firstname`,`model_lastname`,`model_birthdate`,`model_remarks`,`model_setcount`, `model_firstset`, `model_lastset`\n\t\t\t\tFROM\n\t\t\t\t\t`vw_Model`\n\t\t\t\tWHERE\n\t\t\t\t\tmut_deleted = -1\t\n\t\t\t\t\t%1\$s\n\t\t\t\tORDER BY\n\t\t\t\t\t%2\$s\n\t\t\t\t%3\$s", $SearchParameters->getWhere(), $OrderClause, $LimitClause ? ' LIMIT ' . $LimitClause : NULL);
     if (!($stmt = $dbi->prepare($q))) {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
     DBi::BindParamsToSelect($SearchParameters, $stmt);
     if ($stmt->execute()) {
         $OutArray = array();
         $stmt->bind_result($model_id, $model_firstname, $model_lastname, $model_birthdate, $model_remarks, $model_setcount, $model_firstset, $model_lastset);
         while ($stmt->fetch()) {
             $o = new self($model_id, $model_firstname, $model_lastname, $model_birthdate, $model_remarks, $model_setcount, $model_firstset, $model_lastset);
             $OutArray[] = $o;
         }
         $stmt->close();
         return $OutArray;
     } else {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
 }
Esempio n. 9
0
 /**
  * Gets an array of Users from the database, or NULL on failure.
  * @param UserSearchParameters $SearchParameters
  * @param string $OrderClause
  * @param string $LimitClause
  * @return array(User) | NULL
  */
 public static function GetUsers($SearchParameters = NULL, $OrderClause = 'user_lastname ASC, user_firstname ASC', $LimitClause = NULL)
 {
     global $dbi;
     $SearchParameters = $SearchParameters ? $SearchParameters : new UserSearchParameters();
     $OrderClause = empty($OrderClause) ? 'user_lastname ASC, user_firstname ASC' : $OrderClause;
     $q = sprintf("\n\t\t\tSELECT\n\t\t\t\t`user_id`, `user_username`, `user_password`, `user_salt`,\n\t\t\t\t`user_firstname`, `user_insertion`, `user_lastname`, `user_email`,\n\t\t\t\t`user_gender`, `user_birthdate`,\n\t\t\t\t`user_datedisplayopts`, `user_imageview`, `user_language`, `user_rights`,\n\t\t\t\t`user_lastactive`, `user_lastlogin`, `user_prelastlogin`\n\t\t\tFROM\n\t\t\t\t`User`\n\t\t\tWHERE\n\t\t\t\tmut_deleted = -1\n\t\t\t\t%1\$s\n\t\t\tORDER BY\n\t\t\t\t%2\$s\n\t\t\t%3\$s", $SearchParameters->getWhere(), $OrderClause, $LimitClause ? ' LIMIT ' . $LimitClause : NULL);
     if (!($stmt = $dbi->prepare($q))) {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
     DBi::BindParamsToSelect($SearchParameters, $stmt);
     if ($stmt->execute()) {
         $OutArray = array();
         $stmt->bind_result($user_id, $user_username, $user_password, $user_salt, $user_firstname, $user_insertion, $user_lastname, $user_email, $user_gender, $user_birthdate, $user_datedisplayopts, $user_imageview, $user_language, $user_rights, $user_lastactive, $user_lastlogin, $user_prelastlogin);
         while ($stmt->fetch()) {
             // Unserialize the non-NULL value in the db, catch dev-time INT
             $user_rights = $user_rights && !is_numeric($user_rights) ? unserialize($user_rights) : array();
             $o = new self($user_id, $user_username, $user_password, $user_salt, $user_firstname, $user_insertion, $user_lastname, $user_email, $user_gender, $user_birthdate, $user_datedisplayopts, $user_imageview, $user_language, $user_rights, $user_lastactive, $user_lastlogin, $user_prelastlogin);
             $OutArray[] = $o;
         }
         $stmt->close();
         return $OutArray;
     } else {
         $e = new SQLerror($dbi->errno, $dbi->error);
         Error::AddError($e);
         return NULL;
     }
 }
Esempio n. 10
0
 $CandyPath = isset($_POST['txtCandyPath']) && strlen($_POST['txtCandyPath']) > 0 ? (string) $_POST['txtCandyPath'] : NULL;
 $CandyVideoThumbPath = isset($_POST['txtCandyVideoThumbPath']) && strlen($_POST['txtCandyVideoThumbPath']) > 0 ? (string) $_POST['txtCandyVideoThumbPath'] : NULL;
 $UseMailServer = array_key_exists('chkUseMailServer', $_POST);
 $SmtpFromAddress = isset($_POST['txtSmtpFromAddress']) && strlen($_POST['txtSmtpFromAddress']) > 0 ? (string) $_POST['txtSmtpFromAddress'] : NULL;
 $SmtpFromName = isset($_POST['txtSmtpFromName']) && strlen($_POST['txtSmtpFromName']) > 0 ? (string) $_POST['txtSmtpFromName'] : NULL;
 $SmtpHostname = isset($_POST['txtSmtpHostname']) && strlen($_POST['txtSmtpHostname']) > 0 ? (string) $_POST['txtSmtpHostname'] : NULL;
 $SmtpUsername = isset($_POST['txtSmtpUsername']) && strlen($_POST['txtSmtpUsername']) > 0 ? (string) $_POST['txtSmtpUsername'] : NULL;
 $SmtpPassword = isset($_POST['txtSmtpPassword']) && strlen($_POST['txtSmtpPassword']) > 0 ? (string) $_POST['txtSmtpPassword'] : NULL;
 $SmtpPort = isset($_POST['txtSmtpPort']) && intval($_POST['txtSmtpPort']) > 0 ? intval($_POST['txtSmtpPort']) : 0;
 $SmtpAuth = array_key_exists('chkSmtpAuth', $_POST);
 $PasswordOK = $_POST['txtRepeatPassword'] == $_POST['txtPassword'];
 $EmailOK = Utils::ValidateEmail($UserEmail);
 $DBsettingsSet = isset($DBHostName) && isset($DBUserName) && isset($DBPassword);
 if ($PasswordOK && $EmailOK && $DBsettingsSet) {
     /* @var $dbi DBi */
     if (@($dbi = new DBi($DBHostName, $DBUserName, $DBPassword, 'mysql'))) {
         $DBConnectOK = $dbi->connect_errno == 0;
         if ($DBConnectOK) {
             if ($dbi->ExecuteMulti(sprintf($CreateDBSQL, $dbi->real_escape_string($DBName)))) {
                 $UserSalt = Utils::GenerateGarbage(20);
                 if ($dbi->query(sprintf($InsertUserSQL, $dbi->real_escape_string($UserName), $dbi->real_escape_string(Utils::HashString($Password, $UserSalt)), $dbi->real_escape_string($UserSalt), $dbi->real_escape_string($UserFirstName), $dbi->real_escape_string($UserLastName), $dbi->real_escape_string($UserEmail), $dbi->real_escape_string(serialize(Rights::getTotalRights()))))) {
                     $NewUserID = $dbi->insert_id;
                     $NewConfig = sprintf($ConfigTemplate, str_ireplace('\\', '\\\\', $CandyPath), str_ireplace('\\', '\\\\', $CandyVideoThumbPath), $DBHostName, $DBUserName, $DBPassword, $DBName, $NewUserID, $SmtpFromAddress, $SmtpFromName, $SmtpHostname, $SmtpUsername, $SmtpPassword, $SmtpPort, $SmtpAuth ? 'TRUE' : 'FALSE', $UserFirstName, $UserLastName);
                     if (@file_put_contents('config.php', $NewConfig, LOCK_EX) !== FALSE) {
                         if (is_dir('cache') || mkdir('cache', 0700, TRUE)) {
                             $i = new Info($lang->g('MessageAllDoneConfigWritten'));
                             Info::AddInfo($i);
                             header('location:login.php');
                             exit;
                         } else {
                             $e = new Error(NULL, $lang->g('ErrorSetupCreatingCacheDir'));