Example #1
0
 private static function save($user_id, $username, $password)
 {
     if ($user_id * 1 === -1) {
         $user = new user();
         $user->username = $username;
         $user->password = md5($password);
         $user->insert();
     } else {
         $user = new user();
         $user->id = $user_id;
         $user->username = $username;
         $user->password = md5($password);
         $user->update();
     }
 }
Example #2
0
function createuser($obj)
{
    try {
        $user = new user();
        $name = isset($obj->name) ? $obj->name : '';
        $password = isset($obj->password) ? $obj->password : '';
        $group_id = isset($obj->group_id) ? $obj->group_id : 0;
        $id = $user->insert($name, $password, $group_id);
        if (isset($id)) {
            return array("status" => "success", "msg" => "Create Successful");
        } else {
            return array("status" => "warning", "msg" => "Create Fail");
        }
    } catch (Exception $e) {
        return array("status" => "warning", "msg" => $e->getMessage());
    }
}
Example #3
0
 public function add($_GET, $_POST)
 {
     $result = 0;
     switch ($_GET['p']) {
         case 'user':
             $user = new user();
             $result = $user->insert($_POST);
             break;
         default:
             $obj = new $_GET['p']();
             $result = $obj->insert($_POST);
             break;
     }
     if ($result) {
         $arr = array('statusCode' => 200, 'message' => "添加成功", 'navTabId' => "", 'rel' => "", 'callbackType' => "closeCurrent", "forwardUrl" => "");
     } else {
         $arr = array('statusCode' => 300, 'message' => "操作失败", 'navTabId' => "", 'rel' => "", 'callbackType' => "closeCurrent", "forwardUrl" => "");
     }
     return $arr;
 }
Example #4
0
 public function add($GET, $POST)
 {
     $result = 0;
     switch ($GET['p']) {
         case 'user':
             $user = new user();
             $result = $user->insert($POST);
             break;
         case 'test':
             $test = new test();
             $result = $test->insert($POST);
             break;
         default:
             //$this->common_add($_POST,$thepage);
             break;
     }
     if ($result) {
         $arr = array('statusCode' => 200, 'message' => "添加成功", 'navTabId' => "", 'rel' => "", 'callbackType' => "closeCurrent", "forwardUrl" => "");
     } else {
         $arr = array('statusCode' => 300, 'message' => "操作失败", 'navTabId' => "", 'rel' => "", 'callbackType' => "closeCurrent", "forwardUrl" => "");
     }
     return $arr;
 }
Example #5
0
 public function index($name = '')
 {
     //	$user = $this->model('User');
     //	$user->name = $name;
     if (empty($name)) {
         echo 'sex';
         //$this->view('help/index');
         print_r($_POST);
     } else {
         require_once '../app/models/user.php';
         $db = new user();
         //print_r($_POST);
         foreach ($_POST as $key => $value) {
             $dane = explode(' ', $value);
             //print_r($dane);
             if ($dane[1] == 'NULL') {
                 $dane[1] = NULL;
             }
             $db->insert("INSERT INTO klienci (name,email,system) VALUES ('" . $dane[0] . "','" . $dane[1] . "','" . $dane[2] . "')");
         }
         header('Location: http://localhost/wwwv2.0/mvcbeta/public/');
         //$this->view('help/index',$name);
     }
 }
Example #6
0
<?php

include "../Code/MongoHelper.php";
/**
 * Define user class, MongoHelper will fallback to defaults if no configurations is given
 * This will use "user" collection by default
 * @author juhatauriainen
 */
class user extends MongoHelper
{
}
$user = new user();
// insert some rows
$user->insert(array("username" => "Pekka", "city" => "Helsinki", "sex" => "Yes please"));
$user->insert(array("username" => "Simo", "city" => "Helsinki"));
$user->insert(array("username" => "Jaana", "city" => "Tampere"));
$user->insert(array("username" => "Bill", "city" => "Seattle"));
// find single row
$pekka = $user->findOne(array("username" => "Pekka"));
echo '<p>Found ' . $pekka['username'] . ' from ' . $pekka['city'] . '</p>';
// fetch all rows
$rows = $user->getAll();
echo '<p>Found ' . $rows->count() . ' rows</p>';
foreach ($rows as $row) {
    echo '<p>Found ' . $row['username'] . ' from ' . $row['city'] . '</p>';
}
// sort users by username
$rows->sort(array("username" => -1));
echo '<p>Sorting users</p>';
foreach ($rows as $row) {
    echo '<p>Found ' . $row['username'] . ' from ' . $row['city'] . '</p>';
Example #7
0
    echo $language['save'];
    ?>
</button>
			  <button type="reset" name="cancel"><?php 
    echo $language['cancel'];
    ?>
</button>
		</div>
	</form>
	<?php 
} else {
    if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $user = new user();
        $user->setUsername($_POST['username']);
        $user->setPassword($_POST['password']);
        $user->setEmail($_POST['email']);
        $user->setRank($_POST['rank']);
        if ($user->existUserByName() == 0) {
            if ($user->insert()) {
                print 'sucess';
            } else {
                print 'failure';
            }
        } else {
            print 'O username ja existe';
        }
    } else {
        print 'Email invalido';
        print '<script type="text/javascript">setTimeout(goBack(),2000);</script>';
    }
}
Example #8
0
<?php

require 'db-connect.php';
require 'user.php';
if (isset($_POST['userName'])) {
    //        echo " inside the insert function";
    $user = new user();
    // echo $_POST['userName'];
    $user->userName = $db->escape_string($_POST['userName']);
    $user->password = $db->escape_string($_POST['password']);
    $user->email = $db->escape_string($_POST['email']);
    // $user->photo = $db->escape_string($_POST['photo']);
    //        $product->photo = ($_FILES['photo']['name']);
    // $photo_tmp = $_FILES['photo']['tmp_name'];
    // move_uploaded_file($photo_tmp, "../images/$user->photo");
    // Form Validation Requiered in advance.
    $user->insert();
    header('location:../login/index.php');
}
Example #9
0
function process()
{
    global $DB;
    global $website;
    global $events;
    global $theme;
    set_time_limit(0);
    setlocale(LC_ALL, $_SESSION['navigate_install_locale']);
    $lang = navigate_install_load_language();
    switch ($_REQUEST['process']) {
        case 'verify_zip':
            sleep(1);
            if (!file_exists('package.zip')) {
                die(json_encode($lang['missing_package']));
            } else {
                $zip = new ZipArchive();
                if ($zip->open('package.zip') !== TRUE) {
                    die(json_encode($lang['invalid_package']));
                } else {
                    $zip->close();
                    die(json_encode(true));
                }
            }
            break;
        case 'extract_zip':
            $npath = getcwd() . NAVIGATE_FOLDER;
            $npath = str_replace('\\', '/', $npath);
            if (!file_exists($npath)) {
                mkdir($npath);
            }
            if (file_exists($npath)) {
                $zip = new ZipArchive();
                if ($zip->open('package.zip') === TRUE) {
                    $zip->extractTo($npath);
                    $zip->close();
                    copy($npath . '/crossdomain.xml', dirname($npath) . '/crossdomain.xml');
                    die(json_encode(true));
                } else {
                    die(json_encode($lang['extraction_failed']));
                }
            }
            die(json_encode($lang['folder_not_exists']));
            break;
        case 'chmod':
            sleep(1);
            // chmod the directories recursively
            $npath = getcwd() . NAVIGATE_FOLDER;
            if (!navigate_install_chmodr($npath, 0755)) {
                die(json_encode($lang['chmod_failed']));
            } else {
                die(json_encode(true));
            }
            break;
        case 'verify_database':
            if ($_REQUEST['PDO_DRIVER'] == 'mysql' || $_REQUEST['PDO_DRIVER'] == 'mysql-socket') {
                try {
                    $dsn = "mysql:host=" . $_REQUEST['PDO_HOSTNAME'] . ";port=" . $_REQUEST['PDO_PORT'] . ';charset=utf8';
                    if ($_REQUEST['PDO_DRIVER'] == "mysql-socket") {
                        $dsn = "mysql:unix_socket=" . $_REQUEST['PDO_SOCKET'] . ";charset=utf8";
                    }
                    $db_test = @new PDO($dsn, $_REQUEST['PDO_USERNAME'], $_REQUEST['PDO_PASSWORD']);
                    if (!$db_test) {
                        echo json_encode(array('error' => $lang['database_connect_error']));
                    } else {
                        $create_database_privilege = false;
                        $drop_database_privilege = false;
                        $stm = $db_test->query('SHOW DATABASES;');
                        $rs = $stm->fetchAll(PDO::FETCH_COLUMN, 'Database');
                        $rs = array_diff($rs, array('mysql', 'information_schema'));
                        $stm = $db_test->query('SHOW PRIVILEGES;');
                        $privileges = $stm->fetchAll(PDO::FETCH_ASSOC);
                        for ($p = 0; $p < count($privileges); $p++) {
                            if ($privileges[$p]['Privilege'] == 'Create') {
                                if (strpos($privileges[$p]['Context'], 'Databases') !== false) {
                                    $create_database_privilege = true;
                                }
                            }
                            if ($privileges[$p]['Privilege'] == 'Drop') {
                                if (strpos($privileges[$p]['Context'], 'Databases') !== false) {
                                    $drop_database_privilege = true;
                                }
                            }
                        }
                        if ($create_database_privilege && $drop_database_privilege) {
                            // check if we are really allowed to create databases
                            $dbname = 'navigate_test_' . time();
                            $create_result = $db_test->exec('CREATE DATABASE ' . $dbname);
                            if ($create_result) {
                                $db_test->exec('DROP DATABASE ' . $dbname);
                            }
                            if (!$create_result) {
                                $create_database_privilege = false;
                            }
                        }
                        $db_test = NULL;
                        echo json_encode(array('databases' => array_values($rs), 'create_database_privilege' => $create_database_privilege));
                    }
                } catch (Exception $e) {
                    echo json_encode(array('error' => $e->getMessage()));
                }
            } else {
                echo json_encode(array('error' => $lang['database_driver_error']));
            }
            exit;
            break;
        case 'database_create':
            $DB = new database();
            if (!$DB->connect()) {
                // try to create the database automatically
                if (PDO_DRIVER == 'mysql') {
                    if (PDO_DATABASE != '') {
                        if (PDO_HOSTNAME != "") {
                            $dsn = "mysql:host=" . PDO_HOSTNAME . ";port=" . PDO_PORT . ";charset=utf8";
                        } else {
                            $dsn = "mysql:unix_socket=" . PDO_SOCKET . ";charset=utf8";
                        }
                        $db_test = new PDO($dsn, PDO_USERNAME, PDO_PASSWORD);
                        $db_test->exec('CREATE DATABASE IF NOT EXISTS `' . PDO_DATABASE . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
                        $db_test = NULL;
                    }
                    if (!$DB->connect()) {
                        echo json_encode(array('error' => $DB->get_last_error()));
                    } else {
                        echo json_encode(array('ok' => $lang['database_created']));
                    }
                }
            } else {
                echo json_encode(array('ok' => $lang['database_exists']));
            }
            exit;
            break;
        case 'database_import':
            $DB = new database();
            if (!$DB->connect()) {
                die(json_encode(array('error' => $DB->get_last_error())));
            }
            try {
                $sql = file_get_contents('navigate.sql');
                $sql = str_replace("{#!NAVIGATE_FOLDER!#}", NAVIGATE_PARENT . NAVIGATE_FOLDER, $sql);
                $sql = explode("\n\n", $sql);
                // can't do it in one step => SQLSTATE[HY000]: General error: 2014
                foreach ($sql as $sqlline) {
                    $sqlline = trim($sqlline);
                    if (empty($sqlline)) {
                        continue;
                    }
                    if (!@$DB->execute($sqlline)) {
                        $error = $DB->get_last_error();
                    }
                    if (!empty($error)) {
                        break;
                    }
                }
            } catch (Exception $e) {
                $error = $e->getMessage();
            }
            if (!empty($error) && false) {
                echo json_encode(array('error' => $error));
            } else {
                echo json_encode(array('ok' => $lang['done']));
            }
            exit;
            break;
        case 'create_account':
            // create admin
            try {
                $DB = new database();
                if (!$DB->connect()) {
                    die(json_encode(array('error' => $DB->get_last_error())));
                }
                $user = new user();
                $user->id = 0;
                $user->username = $_SESSION['NAVIGATE-SETUP']['ADMIN_USERNAME'];
                $user->set_password($_SESSION['NAVIGATE-SETUP']['ADMIN_PASSWORD']);
                $user->email = $_SESSION['NAVIGATE-SETUP']['ADMIN_EMAIL'];
                $user->profile = 1;
                $user->skin = 'cupertino';
                $user->language = $_SESSION['navigate_install_lang'];
                $user->blocked = 0;
                $user->timezone = 'UTC';
                $user->date_format = 'Y-m-d H:i';
                $user->decimal_separator = ',';
                $user->thousands_separator = '';
                $user->attempts = 0;
                $user->cookie_hash = '';
                $user->activation_key = '';
                $ok = $user->insert();
                if (!$ok) {
                    throw new Exception($lang['error']);
                }
                // create default website details
                $website = new website();
                $website->create_default();
                $_SESSION['NAVIGATE-SETUP']['WEBSITE_DEFAULT'] = $website->id;
                echo json_encode(array('ok' => $lang['done']));
            } catch (Exception $e) {
                echo json_encode(array('error' => $e->getMessage()));
            }
            exit;
            break;
        case 'install_default_theme':
            try {
                $DB = new database();
                if (!$DB->connect()) {
                    die(json_encode(array('error' => $DB->get_last_error())));
                }
                if (@$_SESSION['NAVIGATE-SETUP']['DEFAULT_THEME'] == 'theme_kit') {
                    $website = new website();
                    $website->load($_SESSION['NAVIGATE-SETUP']['WEBSITE_DEFAULT']);
                    $website->theme = 'theme_kit';
                    $website->languages = array('en' => array('language' => 'en', 'variant' => '', 'code' => 'en', 'system_locale' => 'en_US.utf8'), 'es' => array('language' => 'es', 'variant' => '', 'code' => 'es', 'system_locale' => 'es_ES.utf8'));
                    $website->languages_published = array('en', 'es');
                    $website->save();
                    // default objects (first user, no events bound...)
                    $user = new user();
                    $user->load(1);
                    $events = new events();
                    $zip = new ZipArchive();
                    $zip_open_status = $zip->open(NAVIGATE_PATH . '/themes/theme_kit.zip');
                    if ($zip_open_status === TRUE) {
                        $zip->extractTo(NAVIGATE_PATH . '/themes/theme_kit');
                        $zip->close();
                        $theme = new theme();
                        $theme->load('theme_kit');
                        $theme->import_sample($website);
                    }
                    echo json_encode(array('ok' => $lang['done']));
                } else {
                    // user does not want to install the default theme
                    echo json_encode(array('ok' => $lang['not_selected']));
                }
            } catch (Exception $e) {
                echo json_encode(array('error' => $e->getMessage()));
            }
            exit;
            break;
        case 'apache_htaccess':
            try {
                $nvweb = dirname($_SERVER['REQUEST_URI']) . NAVIGATE_FOLDER . '/web/nvweb.php';
                $nvweb = str_replace('//', '/', $nvweb);
                $data = array();
                $data[] = 'Options +FollowSymLinks';
                $data[] = 'Options -Indexes';
                $data[] = 'RewriteEngine On';
                $data[] = 'RewriteBase /';
                $data[] = 'RewriteCond %{REQUEST_FILENAME} !-f';
                $data[] = 'RewriteCond %{REQUEST_FILENAME} !-d';
                $data[] = 'RewriteRule ^(.+) ' . $nvweb . '?route=$1 [QSA]';
                $data[] = 'RewriteRule ^$ ' . $nvweb . '?route=nv.empty [L,QSA]';
                $ok = @file_put_contents(dirname(NAVIGATE_PATH) . '/.htaccess', implode("\n", $data));
                if (!$ok) {
                    throw new Exception($lang['unexpected_error']);
                }
                echo json_encode('true');
            } catch (Exception $e) {
                echo json_encode(array('error' => $e->getMessage()));
            }
            exit;
            break;
    }
}
Example #10
0
$userInst = new user();
#######################################################################
## perform action
$status = 1;
if (tool::securePost('action') && tool::securePost('action') == "save" && tool::securePost('id') && tool::securePost('id') != "") {
    # fill user with submitted data
    $userInst->id = tool::securePost('id');
    $userInst->fill(tool::securePostAll());
    if (!DEMO_MODE) {
        $status = $userInst->update();
    } else {
        $toolInst->errorStatus("not allowed in this demo. Sorry ;)");
    }
} elseif (tool::securePost('action') && tool::securePost('action') == "save") {
    $userInst->fill(tool::securePostAll());
    $status = $userInst->insert();
}
if (tool::securePost('action') && tool::securePost('action') == "delete" && tool::securePost('id') && tool::securePost('id') != "") {
    $userInst->id = tool::securePost('id');
    if (!DEMO_MODE) {
        $userInst->delete();
    } else {
        $toolInst->errorStatus("not allowed in this demo. Sorry ;)");
    }
}
if (tool::securePost('action') && tool::securePost('action') == "edit" && tool::securePost('id') && tool::securePost('id') != "") {
    $status = 0;
    $userInst->activate(tool::securePost('id'));
}
#######################################################################
## make edit / new form