Example #1
0
function db_query($q)
{
    global $DB_NAME, $DB_USEOLDLIB;
    $conn = db_connect();
    if (!$conn) {
        return false;
    }
    if ($DB_USEOLDLIB) {
        mysql_select_db($DB_NAME);
        $retval = mysql_query($q, $conn);
    } else {
        $retval = $conn->query($q);
    }
    if (!$retval) {
        return false;
    }
    $res = array();
    // this may not be needed, since $retval already is an array
    $row = null;
    if ($DB_USEOLDLIB) {
        while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
            array_push($res, $row);
        }
    } else {
        while ($row = mysqli_fetch_array($retval, MYSQL_ASSOC)) {
            array_push($res, $row);
        }
    }
    db_close($conn);
    return $res;
}
Example #2
0
function main()
{
    // создаем сессию
    session_start();
    if (is_current_user()) {
        // если пользователь уже залогинен, то отправляем его на глапную
        redirect('./');
    }
    if (is_postback()) {
        // обрабатываем отправленную форму
        $dbh = db_connect();
        $post_result = register_user($dbh, $user, $errors);
        db_close($dbh);
        if ($post_result) {
            // перенаправляем на главную
            redirect('./');
        } else {
            // информация о пользователе заполнена неправильно, выведем страницу с ошибками
            render('register_form', array('form' => $_POST, 'errors' => $errors));
        }
    } else {
        // отправляем пользователю чистую форму для регистрации
        render('register_form', array('form' => array(), 'errors' => array()));
    }
}
Example #3
0
/**
 * return array of the courses associated to a netid
 *
 * @param string $netid
 * @return array key: course code; value: course description
 */
function courses_list($netid)
{
    // prepared requests
    $statements = array('course_all_get' => 'SELECT DISTINCT ' . db_gettable('courses') . '.course_code AS mnemonic, ' . db_gettable('courses') . '.course_name AS label ' . 'FROM ' . db_gettable('courses') . ' ' . 'ORDER BY mnemonic ASC', 'user_courses_get' => 'SELECT DISTINCT ' . db_gettable('users_courses') . '.ID, ' . db_gettable('courses') . '.course_code, ' . db_gettable('courses') . '.shortname, ' . db_gettable('courses') . '.course_name, ' . db_gettable('courses') . '.in_recorders, ' . db_gettable('users_courses') . '.origin ' . 'FROM ' . db_gettable('courses') . ' ' . 'INNER JOIN ' . db_gettable('users_courses') . ' ON ' . db_gettable('courses') . '.course_code = ' . db_gettable('users_courses') . '.course_code ' . 'WHERE user_ID = :user_ID');
    $db = db_prepare($statements);
    if (!$db) {
        debuglog("could not connect to sgbd:" . mysql_error());
        die;
    }
    $result = array();
    if ($netid == "") {
        // retrieves all courses in the database
        $course_list = db_courses_all_get();
        $result = array();
        foreach ($course_list as $value) {
            $result[$value['mnemonic']] = $value['mnemonic'] . '|' . $value['label'];
        }
    } else {
        // retrieves all courses for a given netid
        $course_list = db_user_courses_get($netid);
        $result = array();
        foreach ($course_list as $value) {
            $result[$value['course_code']] = $value['course_code'] . '|' . $value['course_name'];
        }
    }
    db_close();
    return $result;
}
Example #4
0
    function Bod_Ver($opcion) {
        /* El OPTION es para saber si queremos ver el LISTADO de bodegas o SOLO UNA bodega.
         * true = SOLO UNA
         * false = LISTADO
         */
        if ($opcion == false) {
            $queryBodegaVer = "SELECT Bodega_ID, Ubicacion, Descripcion_Bod FROM bodega ORDER BY Bodega_ID;";
        } else {
            $queryBodegaVer = "SELECT Bodega_ID, Ubicacion, Descripcion_Bod FROM bodega WHERE Bodega_ID = $this->bodega_id;";
        }

        db_connect();

        $resultset = mysql_query($queryBodegaVer);

        if ($resultset == false) {
            $return = false;
        } else {
            $contador_array = 0;

            while ($row = mysql_fetch_array($resultset)) {
                $bodega[$contador_array][0] = $row["Bodega_ID"];
                $bodega[$contador_array][1] = $row["Ubicacion"];
                $bodega[$contador_array][2] = $row["Descripcion_Bod"];
                $contador_array++;
            }
            $return = $bodega;
        }
        db_close();
        return $return;
    }
Example #5
0
/**
 * Return all booking headers for the supplied date
 * @param $bdate [in] the date
 * @param $rs [in/out] The result array of headers
 * 
 * @return Number of elements added to RS $rs
 * $rs[idx]['Id'] = Booking Id
 * $rs[idx]['Date'] = Booking date
 * $rs[idx]['Time'] = Booking time
 * $rs[idx]['Name'] = Guest Name
 */
function GetBookingDataForDate($bdate, &$rs)
{
    $conn = connect_Hotel_db(HOST, USER, PASS, DB, PORT);
    if (!$conn) {
        print "Cannot connect to database<br>\n";
    }
    $rs = array();
    $sql = "SELECT g.lastname,g.firstname,g.middlename,b.booking_type,b.checkout_date AS CODate, TIME(b.codatetime) AS COTime, b.book_id\n\t\tFROM guests g RIGHT OUTER JOIN booking b ON g.guestid=b.guestid\n\t\tWHERE b.checkout_date='" . $bdate . "'\n\t\tORDER BY COTime ASC ";
    if (DEBUG) {
        print "Debug BOOKING QRY " . $sql . "<br>\n";
    }
    $result = mysql_query($sql, $conn);
    $i = 0;
    while ($row = mysql_fetch_assoc($result)) {
        if (DEBUG) {
            print "DEBUG Booking " . $row['CODate'] . $row['COTime'] . "<br>\n";
        }
        $rs[$i]['Id'] = $row['book_id'];
        $rs[$i]['Date'] = $row['CODate'];
        $rs[$i]['Time'] = $row['COTime'];
        $rs[$i]['Name'] = $row['lastname'] . "," . $row['firstname'] . " " . $row['middlename'];
        $i++;
    }
    db_close($conn);
    return sizeof($rs);
}
Example #6
0
function main()
{
    session_start();
    // обрабатываем отправленную форму
    //Если передан гет запрос, то открыть запрашиваемую страницу,
    //иначе открыть категорию catgory_id=1
    $dbh = db_connect();
    if (is_current_user()) {
        $count_in_car = product_count_in_car($dbh);
    } else {
        $count_in_car = array();
    }
    if (is_postbuy()) {
        if (is_current_user()) {
            $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']);
            db_product_incar_insert($dbh, $product);
        } else {
            redirect('login.php');
        }
    }
    /*Если передан поисковой запрос и он не пустой, то находим товар по введенному поисковому запросу */
    if (is_getfind()) {
        $items_result = db_product_find_like_title($dbh, $_GET['search_text']);
        $search_text = $_GET['search_text'];
        if ($items_result == null) {
            $items_result = 'products_not_found';
        }
    } else {
        $items_result = null;
        $search_text = null;
    }
    $category_items = db_product_find_category_all($dbh);
    db_close($dbh);
    render('Find_Template', array('items' => $items_result, 'category' => $category_items, 'count_in_car' => $count_in_car, 'search_text' => $search_text));
}
Example #7
0
function url_change($redirect = "")
{
    global $_josh, $_POST;
    if ($redirect === false) {
        //if redirect is really set to FALSE, send to site home
        $redirect = "/";
    } elseif (empty($redirect)) {
        //if redirect is an empty string, refresh the page by sending back to same URL
        $redirect = $_josh["request"]["path_query"];
    }
    if ($_josh["slow"]) {
        error_debug("<b>url_change</b> (slow) to " . $redirect);
        if ($_josh["debug"]) {
            db_close();
        }
        echo "<html><head>\n\t\t\t\t<script language='javascript'>\n\t\t\t\t\t<!--\n\t\t\t\t\tlocation.href='" . $redirect . "';\n\t\t\t\t\t//-->\n\t\t\t\t</script>\n\t\t\t</head><body></body></html>";
    } else {
        error_debug("<b>url_change</b> (fast) to " . $redirect);
        if ($_josh["debug"]) {
            db_close();
        }
        header("Location: " . $redirect);
    }
    db_close();
}
Example #8
0
function DoWapShowMsg($error, $returnurl = 'index.php', $ecms = 0)
{
    global $empire, $public_r;
    $gotourl = str_replace('&amp;', '&', $returnurl);
    if (strstr($gotourl, "(") || empty($gotourl)) {
        if (strstr($gotourl, "(-2")) {
            $gotourl_js = "history.go(-2)";
            $gotourl = "javascript:history.go(-2)";
        } else {
            $gotourl_js = "history.go(-1)";
            $gotourl = "javascript:history.go(-1)";
        }
    } else {
        $gotourl_js = "self.location.href='{$gotourl}';";
    }
    if ($ecms == 9) {
        echo "<script>alert('" . $error . "');" . $gotourl_js . "</script>";
    } elseif ($ecms == 7) {
        echo "<script>alert('" . $error . "');window.close();</script>";
    } else {
        @(include ECMS_PATH . DASHBOARD . '/wap/message.php');
    }
    db_close();
    $empire = null;
    exit;
}
function execQuery($query)
{
    $conn = db_open();
    $rs = mysql_query($query, $conn);
    // or die (mysql_error());
    db_close($conn);
    return $rs;
}
Example #10
0
function ReNewsHtml($start, $classid, $from, $retype, $startday, $endday, $startid, $endid, $tbname, $havehtml)
{
    global $empire, $public_r, $class_r, $fun_r, $dbtbpre, $etable_r;
    $tbname = RepPostVar($tbname);
    if (empty($tbname)) {
        printerror("ErrorUrl", "history.go(-1)");
    }
    $start = (int) $start;
    //按ID
    if ($retype) {
        $startid = (int) $startid;
        $endid = (int) $endid;
        $add1 = $endid ? ' and id>=' . $startid . ' and id<=' . $endid : '';
    } else {
        $startday = RepPostVar($startday);
        $endday = RepPostVar($endday);
        $add1 = $startday && $endday ? ' and truetime>=' . to_time($startday . ' 00:00:00') . ' and truetime<=' . to_time($endday . ' 23:59:59') : '';
    }
    //按栏目
    $classid = (int) $classid;
    if ($classid) {
        $where = empty($class_r[$classid][islast]) ? ReturnClass($class_r[$classid][sonclass]) : "classid='{$classid}'";
        $add1 .= ' and ' . $where;
    }
    //不生成
    $add1 .= ReturnNreInfoWhere();
    //是否重复生成
    if ($havehtml != 1) {
        $add1 .= ' and havehtml=0';
    }
    //优化
    $yhadd = '';
    $yhid = $etable_r[$tbname][yhid];
    $yhvar = 'rehtml';
    if ($yhid) {
        $yhadd = ReturnYhSql($yhid, $yhvar);
    }
    $b = 0;
    $sql = $empire->query("select * from {$dbtbpre}ecms_" . $tbname . " where " . $yhadd . "id>{$start}" . $add1 . " and checked=1 order by id limit " . $public_r[renewsnum]);
    while ($r = $empire->fetch($sql)) {
        if (!empty($r['titleurl']) || $class_r[$r[classid]][showdt] == 2) {
            continue;
        }
        $b = 1;
        GetHtml($r, '', 1);
        //生成信息文件
        $new_start = $r[id];
    }
    if (empty($b)) {
        echo "<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><center><b>" . $tbname . $fun_r[ReTableIsOK] . "!</b></center>";
        db_close();
        $empire = null;
        exit;
    }
    echo "<link rel=\"stylesheet\" href=\"../data/images/css.css\" type=\"text/css\"><meta http-equiv=\"refresh\" content=\"" . $public_r['realltime'] . ";url=ecmschtml.php?enews=ReNewsHtml&tbname={$tbname}&classid={$classid}&start={$new_start}&from={$from}&retype={$retype}&startday={$startday}&endday={$endday}&startid={$startid}&endid={$endid}&havehtml={$havehtml}&reallinfotime=" . $_GET['reallinfotime'] . "\">" . $fun_r[OneReNewsHtmlSuccess] . "(ID:<font color=red><b>" . $new_start . "</b></font>)";
    exit;
}
Example #11
0
/**
 * Print the footer <div> for the bottom of all admin pages.
 *
 * @param string $addl additional text to output on the footer.
 * @author Todd Papaioannou (lucky@luckyspin.org)
 * @since  1.0.0
 */
function printAdminFooter($addl = '')
{
    ?>
	<div id="footer">
		<?php 
    printf(gettext('<a href="http://www.zenphoto.org" title="The simpler media website CMS">Zen<strong>photo</strong></a> version %1$s [%2$s]'), ZENPHOTO_VERSION, ZENPHOTO_RELEASE);
    if (!empty($addl)) {
        echo ' | ' . $addl;
    }
    ?>
		| <a href="<?php 
    echo FULLWEBPATH . '/' . ZENFOLDER . '/license.php';
    ?>
" title="<?php 
    echo gettext('Zenphoto licence');
    ?>
"><?php 
    echo gettext('License');
    ?>
</a>
		| <a href="http://www.zenphoto.org/news/category/user-guide" title="<?php 
    echo gettext('User guide');
    ?>
"><?php 
    echo gettext('User guide');
    ?>
</a>
		| <a href="http://www.zenphoto.org/support/" title="<?php 
    echo gettext('Forum');
    ?>
"><?php 
    echo gettext('Forum');
    ?>
</a>
		| <a href="https://github.com/zenphoto/zenphoto/issues" title="<?php 
    echo gettext('Bugtracker');
    ?>
"><?php 
    echo gettext('Bugtracker');
    ?>
</a>
		| <a href="http://www.zenphoto.org/news/category/changelog" title="<?php 
    echo gettext('View Change log');
    ?>
"><?php 
    echo gettext('Change log');
    ?>
</a>
		| <?php 
    printf(gettext('Server date: %s'), date('Y-m-d H:i:s'));
    ?>
	</div>
	<?php 
    db_close();
    //	close the database as we are done
}
/**
 * Print the footer <div> for the bottom of all admin pages.
 *
 * @param string $addl additional text to output on the footer.
 * @author Todd Papaioannou (lucky@luckyspin.org)
 * @since  1.0.0
 */
function printAdminFooter($addl = '')
{
    ?>
	<div id="footer">
		<?php 
    printf(gettext('<a href="http://www.zenphoto.org" title="A simpler web album">Zen<strong>photo</strong></a> version %1$s [%2$s]'), ZENPHOTO_VERSION, ZENPHOTO_RELEASE);
    if (!empty($addl)) {
        echo ' | ' . $addl;
    }
    ?>
		 | <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" title="<?php 
    echo gettext('GPLv2');
    ?>
"><?php 
    echo gettext('License:GPLv2');
    ?>
</a>
		 | <a href="http://www.zenphoto.org/news/category/user-guide" title="<?php 
    echo gettext('User guide');
    ?>
"><?php 
    echo gettext('User guide');
    ?>
</a>
		 | <a href="http://www.zenphoto.org/support/" title="<?php 
    echo gettext('Forum');
    ?>
"><?php 
    echo gettext('Forum');
    ?>
</a>
		 | <a href="http://www.zenphoto.org/trac/report/10" title="<?php 
    echo gettext('Bugtracker');
    ?>
"><?php 
    echo gettext('Bugtracker');
    ?>
</a>
		 | <a href="http://www.zenphoto.org/news/categorychangelog" title="<?php 
    echo gettext('View Change log');
    ?>
"><?php 
    echo gettext('Change log');
    ?>
</a>
		 <br />
		<?php 
    printf(gettext('Server date: %s'), date('Y-m-d H:i:s'));
    ?>
	</div>
	<?php 
    db_close();
    //	close the database as we are done
}
function delete_student($id)
{
    $connection = db_connect();
    $query = "DELETE FROM `student` WHERE `student`.`id` = '{$id}'";
    $result = mysqli_query($connection, $query);
    if ($result) {
        //check if query ran
    } else {
    }
    db_close($connection);
}
Example #14
0
function get_db_results()
{
    $db = db_connect();
    $res = $db->query("SELECT choice FROM ballot_box");
    $out = array();
    while ($obj = $res->fetch_object()) {
        $out[] = $obj->choice;
    }
    $res->close();
    db_close($db);
    return $out;
}
Example #15
0
function getCategories()
{
    $categories = array();
    $dbhandle = db_connect();
    $query = "SELECT CategoryID as id, CategoryName as title FROM Categories";
    $result = $dbhandle->query($query);
    while ($row = $result->fetch_array()) {
        $newcategory = new category($row);
        array_push($categories, $newcategory);
    }
    db_close($dbhandle);
    return $categories;
}
Example #16
0
function get_post($postid)
{
    validate_post_id($postid);
    $con = db_connect();
    $sql = "SELECT * FROM posts WHERE id={$postid}";
    $result = mysql_query($sql);
    $post = null;
    if (mysql_num_rows($result) > 0) {
        $post = mysql_fetch_array($result);
    }
    db_close($con);
    return $post;
}
Example #17
0
function sigint_handler()
{
    global $sock, $argv, $fp, $mch;
    curl_multi_close($mch);
    fclose($fp);
    socket_close($sock);
    unlink("/private/tmp/classmate{$argv['1']}");
    db_close();
    Error::showSeparator();
    Error::setBgColour('#B66');
    Error::generate('debug', "Finished running classmated {$argv['1']} normally");
    Error::setBgColour('#555');
    Error::showSeparator();
}
Example #18
0
function file_download($content, $filename, $extension)
{
    //header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    //header("Cache-Control: public");
    //for IE over SSL
    header("Cache-Control: maxage=1");
    //In seconds
    header("Pragma: public");
    header("Content-Description: File Transfer");
    header("Content-Type: application/octet-stream");
    header("Content-Length: " . strlen($content));
    header("Content-Disposition: attachment; filename=" . format_file_name($filename, $extension));
    echo $content;
    db_close();
}
Example #19
0
/**
 * Print the footer <div> for the bottom of all admin pages.
 *
 * @param string $addl additional text to output on the footer.
 * @author Todd Papaioannou (lucky@luckyspin.org)
 * @since  1.0.0
 */
function printAdminFooter($addl = '')
{
    ?>
	<div id="footer">
		<?php 
    echo gettext('<span class="zenlogo"><a href="https://' . GITHUB . '" title="' . gettext('A simpler media content management system') . '"><img src="' . WEBPATH . '/' . ZENFOLDER . '/images/zen-logo-light.png" /></a></span> ') . sprintf(gettext('version %1$s'), ZENPHOTO_VERSION);
    if (!empty($addl)) {
        echo ' | ' . $addl;
    }
    ?>
		| <a href="<?php 
    echo FULLWEBPATH . '/' . ZENFOLDER . '/license.php';
    ?>
" title="<?php 
    echo gettext('ZenPhoto20 licence');
    ?>
"><?php 
    echo gettext('License');
    ?>
</a>
		| <a href="https://<?php 
    echo GITHUB;
    ?>
/issues" title="<?php 
    echo gettext('Support');
    ?>
"><?php 
    echo gettext('Support');
    ?>
</a>
		| <a href="https://<?php 
    echo GITHUB;
    ?>
/commits/master" title="<?php 
    echo gettext('View Change log');
    ?>
"><?php 
    echo gettext('Change log');
    ?>
</a>
		| <?php 
    printf(gettext('Server date: %s'), date('Y-m-d H:i:s'));
    ?>
	</div>
	<?php 
    db_close();
    //	close the database as we are done
}
function db_query_return($query)
{
    $valid_query = mysql_real_escape_string($query);
    $resultado = false;
    if ($valid_query = false) {
        $resultado = false;
    } else {
        db_connect();
        $resultado = @mysql_query($valid_query);
        if ($resultado != false) {
            $resultado_array = mysql_fetch_assoc($resultado);
        }
        db_close();
    }
    return $resultado;
}
Example #21
0
function main()
{
    session_start();
    /* Если была выполнена отправка формы,  то открыть запрашиваемую страницу,
     * иначе открыть главную страницу
     */
    $dbh = db_connect();
    if (is_postbuy()) {
        if (is_current_user()) {
            $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']);
            db_product_incar_insert($dbh, $product);
        } else {
            redirect('login.php');
        }
    }
    if (is_postback() || is_postbuy()) {
        // обрабатываем отправленную форму
        if (is_current_user()) {
            $count_in_car = product_count_in_car($dbh);
            $car_items = db_get_product_in_car_by_user($dbh);
            /*Добавлен ли продукт в корзин пользователя? */
            /* Если корзина пустая, то в массиве хранится  значение
               Array ( [0] => Array ( [total] => 0 ) ), отсюда получается следующий оператор) исправлю потом */
            if ($car_items[0]['total'] !== 0) {
                foreach ($car_items as $car_item) {
                    $car_productid[] = $car_item[0]['id'];
                }
            } else {
                $car_productid[] = null;
            }
        } else {
            $count_in_car = array();
            $car_productid[] = null;
        }
        /*Вывести на страницу товар id которго передан либо гетом(Когда нажали на ссылку товара из других страниц), либо постом(Когда товар купили) */
        if (is_postback()) {
            $items_result = db_product_find_by_product_id($dbh, $_GET['product_id']);
        } elseif (is_postbuy()) {
            $items_result = db_product_find_by_product_id($dbh, $_POST['buy_product_id']);
        }
        $category_items = db_product_find_category_all($dbh);
        db_close($dbh);
        render('Product_Page_Template', array('items' => $items_result, 'category' => $category_items, 'count_in_car' => $count_in_car, 'car_productid' => $car_productid));
    } else {
        redirect('index.php');
    }
}
Example #22
0
function main()
{
    session_start();
    // обрабатываем отправленную форму
    //Если передан гет запрос, то открыть запрашиваемую страницу,
    //иначе открыть категорию catgory_id=1
    $dbh = db_connect();
    if (is_postbuy()) {
        if (is_current_user()) {
            $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']);
            db_product_incar_insert($dbh, $product);
        } else {
            redirect('login.php');
        }
    }
    if (is_current_user()) {
        $count_in_car = product_count_in_car($dbh);
        $car_items = db_get_product_in_car_by_user($dbh);
        /*Добавлен ли продукт в корзин пользователя? */
        /* Если корзина пустая, то в массиве хранится  значение
           Array ( [0] => Array ( [total] => 0 ) ), отсюда получается следующий оператор) исправлю потом */
        if ($car_items[0]['total'] !== 0) {
            foreach ($car_items as $car_item) {
                $car_productid[] = $car_item[0]['id'];
            }
        } else {
            $car_productid[] = null;
        }
    } else {
        $count_in_car = array();
        $car_productid[] = null;
    }
    /* показать выбранную категорию*/
    if (is_postback() || is_postbuy()) {
        if (is_postback()) {
            $items_result = db_product_find_by_category_id($dbh, $_GET['catgory_id']);
        } else {
            $items_result = db_product_find_by_category_id($dbh, $_POST['get_category_id']);
            $_GET['catgory_id'] = $_POST['get_category_id'];
        }
    } else {
        $items_result = db_product_find_by_category_id($dbh, 1);
    }
    $category_items = db_product_find_category_all($dbh);
    db_close($dbh);
    render('Category_Page_Template', array('items' => $items_result, 'category' => $category_items, 'count_in_car' => $count_in_car, 'car_productid' => $car_productid));
}
Example #23
0
function getDbTime()
{
    $dbase = db_open($dbase);
    if (!$dbase) {
        echo "<font class='error'>ERROR</font> : cannot open DB<br>";
        exit;
    }
    $sql = "SELECT UNIX_TIMESTAMP( CONVERT_TZ(now(),@@time_zone,'+0:00') )";
    $res = mysqli_query($dbase, $sql);
    if (!@$res) {
        writelog("error.log", "Wrong query : \" {$sql} \"");
        echo "<font class='error'>ERROR</font> : Wrong query : {$sql}<br><br>";
        exit;
    }
    list($date) = mysqli_fetch_row($res);
    db_close($dbase);
    return $date;
}
Example #24
0
function main()
{
    // создаем сессию
    session_start();
    /**************************************************************************
     * Вывод "Популярное" на страницу и меню
     */
    $dbh = db_connect();
    if (is_postbuy()) {
        if (is_current_user()) {
            $product = array('count' => 1, 'user_id' => $_SESSION['user_id'], 'product_id' => $_POST['buy_product_id']);
            db_product_incar_insert($dbh, $product);
        } else {
            redirect('login.php');
        }
    }
    $items_result = get_popular_products($dbh);
    $category_items = db_product_find_category_all($dbh);
    db_close($dbh);
    /**************************************************************************
     * Регистрация
     */
    if (is_current_user()) {
        // если пользователь уже залогинен, то отправляем его на глапную
        redirect('./');
    }
    if (is_postback()) {
        // обрабатываем отправленную форму
        $dbh = db_connect();
        $post_result = register_user($dbh, $user, $errors);
        db_close($dbh);
        if ($post_result) {
            // перенаправляем на главную
            render('sucsess_register', array());
        } else {
            // информация о пользователе заполнена неправильно, выведем страницу с ошибками
            render('register_form', array('form' => $_POST, 'errors' => $errors, 'items' => $items_result, 'category' => $category_items));
        }
    } else {
        // отправляем пользователю чистую форму для регистрации
        render('register_form', array('form' => array(), 'errors' => array(), 'items' => $items_result, 'category' => $category_items));
    }
}
Example #25
0
function main()
{
    // создаем сессию
    session_start();
    if (!is_current_user()) {
        // отправляем пользователя на страницу входа в систему
        redirect('login.php');
    }
    // у нас есть пользователь, считываем список пользователей из БД, и отображаем его
    // подключаемся к базе данных
    $dbh = db_connect();
    // считываем список пользователей и текущего пользователя
    $user_list = db_user_find_all($dbh);
    $current_user = db_user_find_by_id($dbh, get_current_user_id());
    // выводим результирующую страницу
    render('user_list', array('user_list' => $user_list, 'current_user' => $current_user));
    // закрываем соединение с базой данных
    db_close($dbh);
}
 function LineaVta_Nueva() {
     $registro = new StockBodega($this->lineaVtaObra_cantidad, 0, $this->lineaVtaObra_rut_empleado, $this->lineaVtaObra_material_id, $this->lineaVtaObra_bodega_id);
     $registro->Stock_Quitar();
     if ($registro) {
         $queryLineaVta = "INSERT INTO egreso_material_obra (Bodega_ID, Material_ID, Obra_ID, Rut_Emp, Fecha, Cantidad) 
         VALUES ($this->lineaVtaObra_bodega_id, $this->lineaVtaObra_material_id, $this->lineaVtaObra_ID, '$this->lineaVtaObra_rut_empleado', CURRENT_TIMESTAMP, $this->lineaVtaObra_cantidad)";
         db_connect();
         
         $validar = mysql_query($queryLineaVta);
         
         if ($validar) {
             $return = true;
         } else {
             $return = false;
         }
         db_close();
     }
     return $return;
 }
Example #27
0
function main()
{
    $product = array();
    $errors = empty_errors();
    if (is_postback()) {
        // подключаемся к базе данных
        $dbh = db_connect();
        $post_result = add_product($dbh, $product, $errors);
        db_close($dbh);
        if ($post_result) {
            // перенаправляем на список товаров
            render('sucsess_register', array());
        } else {
            render('BD_ProductInsert_T', array('form' => $_POST, 'file' => $_FILES, 'errors' => $errors));
        }
    } else {
        // отправляем пользователю чистую форму для входа
        render('BD_ProductInsert_T', array('form' => array(), 'errors' => array()));
    }
}
Example #28
0
function db_query($q)
{
    global $DB_NAME;
    $conn = db_connect();
    if (!$conn) {
        return false;
    }
    mysql_select_db($DB_NAME);
    $retval = mysql_query($q, $conn);
    if (!$retval) {
        return false;
    }
    $res = array();
    // this may not be needed, since $retval already is an array
    while ($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
        array_push($res, $row);
    }
    db_close($conn);
    return $res;
}
function login_user($email, $pass)
{
    $pass = sha1($pass);
    $connection = db_connect();
    $query = 'SELECT * FROM `project`.`teacher` WHERE `email` = "' . $email . '" AND pass = "******"';
    //create login query
    $result = mysqli_query($connection, $query);
    //perform login query
    if ($result) {
        //check if query ran
        if (mysqli_num_rows($result) > 0) {
            //if any logins are found
            //session_clear(); //clear current session variables
            //username details
            $resultset = mysqli_fetch_assoc($result);
            //get array of values from database
            $_SESSION['email'] = $resultset['email'];
            //Set details as session variables
            $_SESSION['id'] = $resultset['id'];
            $_SESSION['firstname'] = $resultset['firstname'];
            $_SESSION['lastname'] = $resultset['lastname'];
            $_SESSION['school'] = $resultset['school'];
            add_success($resultset['firstname'] . " " . $resultset['lastname'] . " Logged in Successfully");
            db_close($connection);
            header('location: dashboard/classview.php');
            die;
        } else {
            add_error("Login Incorrect");
            //add error message
            db_close($connection);
            header('location: index.php');
            die;
        }
    } else {
        add_error("Login Mysql didnt work.");
        db_close($connection);
        header('location: index.php');
        die;
    }
}
Example #30
0
function rss_getItems($local = '')
{
    $xml = '';
    srand(time());
    db_connect();
    if (!db_isConnected()) {
        return xml;
    }
    $mails = db_getMailsOf($local . '@pookmail.com', $false);
    while ($e = array_pop($mails)) {
        $xml .= "<item>\n";
        $xml .= "<title>" . $e['subject'] . "</title>\n";
        $xml .= "<guid>" . $e['subject'] . "</guid>\n";
        $xml .= "<link>http://www.pookmail.com/mailbox.php?email=" . $local . "&amp;sid=" . md5(rand()) . "</link>\n";
        $xml .= "<description>" . $e['from'] . "</description>\n";
        //$xml .= "<pubDate>".date("D, j M Y H:i:s Z" , $e['date'])."</pubDate>\n";
        $xml .= "<pubDate>" . date("r", $e['date']) . "</pubDate>\n";
        $xml .= "</item>\n";
    }
    db_close();
    return $xml;
}