Esempio n. 1
0
 /**
  * Validates data submitted in the add form. If the validation fails,
  * displays the add page. Otherwise, creates a new order, saves it and
  * its products to the database and clears the 'cart' session variable. 
  * Redirects to the front page.
  */
 public static function add()
 {
     $params = $_POST;
     date_default_timezone_set('Europe/Helsinki');
     $attributes = array('user_id' => $params['user_id'], 'first_name' => $params['first_name'], 'last_name' => $params['last_name'], 'phone_number' => $params['phone_number'], 'street_address' => $params['street_address'], 'postal_code' => $params['postal_code'], 'city' => $params['city'], 'delivery_method' => $params['delivery_method']);
     $validator = self::order_validator($attributes);
     if ($validator->validate()) {
         $order = new Orders(array('user_id' => $attributes['user_id'], 'order_time' => date('d-m-Y H:i:s'), 'actual_delivery_time' => null, 'delivery_address' => $attributes['street_address'] . ', ' . $attributes['postal_code'] . ' ' . $attributes['city'], 'delivery_method' => $attributes['delivery_method'], 'total_price' => $_SESSION['cart']['price'], 'status' => 'Jonossa'));
         if (!$params['user_id']) {
             $user = array('user_id' => null, 'first_name' => $params['first_name'], 'last_name' => $params['last_name'], 'phone_number' => $params['phone_number']);
             $order->user_id = null;
             $order->user_info = json_encode($user);
         } else {
             $order->user_info = json_encode(Users::findOne($_SESSION['user']));
         }
         if ($order->delivery_method == 'Nouto') {
             $order->agreed_delivery_time = date('d-m-Y H:i:s', strtotime('+15 minutes', strtotime($order->order_time)));
         } else {
             $order->agreed_delivery_time = date('d-m-Y H:i:s', strtotime('+60 minutes', strtotime($order->order_time)));
         }
         $order_id = $order->save();
         self::set_order_products($order_id, $_SESSION['cart']['items']);
         $_SESSION['cart'] = null;
         Redirect::to('/', array('message' => 'Tilauksesi on lähetetty, kiitos!'));
     } else {
         View::make('order/add.html', array('errors' => $validator->errors(), 'user' => $attributes));
     }
 }
Esempio n. 2
0
 public static function get_user_logged_in()
 {
     if (isset($_SESSION['user'])) {
         $user_id = $_SESSION['user'];
         return Users::findOne($user_id);
     }
     return;
 }
Esempio n. 3
0
 public static function isUserSimple($id)
 {
     if (Users::findOne(['id' => $id, 'activate' => '1', 'role' => 1])) {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 4
0
 public static function isUserMaestro($id)
 {
     if (Users::findOne(['id' => $id, 'activate' => '1', 'role' => 'maestro'])) {
         return true;
     } else {
         return false;
     }
 }
Esempio n. 5
0
/**
 * getUser
 * Get user info from db or save fb data to db
 *
 * @param array $fb_user returned by FB request
 *
 * @return object
 **/
function getUser($fb_user)
{
    // check user exists in DB
    $user = Users::findOne($fb_user['id']);
    if (!$user) {
        // save user info
        $user = Users::create();
        $user->id = $fb_user['id'];
        $user->name = $fb_user['name'];
        $user->email = $fb_user['email'];
        $user->save();
    }
    return $user;
}
 /**
  * Delete project
  *
  * @param void
  * @return null
  */
 function delete()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $pid = get_id();
     $u = Users::findOne(array("conditions" => "personal_project_id = {$pid}"));
     if ($u) {
         //flash_error("id: $pid, u: ".$u->getId());
         ajx_current("empty");
         flash_error(lang('cannot delete personal project'));
         return;
         //$this->redirectTo('administration', 'projects');
     }
     $project = Projects::findById(get_id());
     if (!$project instanceof Project) {
         flash_error(lang('project dnx'));
         ajx_current("empty");
         return;
         //$this->redirectTo('administration', 'projects');
     }
     // if
     if (!$project->canDelete(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
         //$this->redirectToReferer(get_url('administration', 'projects'));
     }
     // if
     if (!array_var($_GET, 'confirm')) {
         tpl_assign('project', $project);
         $this->setTemplate('pre_delete');
         return;
     }
     ajx_current("empty");
     try {
         $id = $project->getId();
         $name = $project->getName();
         DB::beginWork();
         $project->delete();
         CompanyWebsite::instance()->setProject(null);
         ApplicationLogs::createLog($project, null, ApplicationLogs::ACTION_DELETE);
         DB::commit();
         flash_success(lang('success delete project', $project->getName()));
         evt_add("workspace deleted", array("id" => $id, "name" => $name));
         ajx_current("start");
     } catch (Exception $e) {
         DB::rollback();
         flash_error($e->getMessage());
         ajx_current("empty");
     }
     // try
     //$this->redirectTo('administration', 'projects');
 }
Esempio n. 7
0
			echo(lang('no access permissions'));
			?><br><a href="<?php echo ROOT_URL?>/index.php?c=access&a=index" target="_top">Go back to Feng Office</a><?php
			return;
		}

		$id = get_id();
		if ($id>0){
			$account = MailAccounts::findById($id);
		}
		else{ 
			$email_address = array_var($_GET, 'email');			
			$user_name = array_var($_GET, 'username');
			if (isset ($email_address) && isset ($user_name)){
				$user_conditions = array("conditions" => array("`username`='".$user_name."'"));
			
				$user = Users::findOne($user_conditions);
			
				if (!isset ($user)){	
					echo(lang('cant find user'));
					?><br><a href="<?php echo ROOT_URL?>/index.php?c=access&a=index" target="_top">Go back to Feng Office</a><?php 		
					return;
				}			
											
				$account_conditions = array("conditions" => array("`email_addr`='".$email_address."' AND `user_id`='".$user->getId()."'"));
				$account = MailAccounts::findOne($account_conditions);
				if (!isset ($account)){		
					echo(lang('cant find account'));
					?><br><a href="<?php echo ROOT_URL?>/index.php?c=access&a=index" target="_top">Go back to Feng Office</a><?php
					return;
				}					
			} 
Esempio n. 8
0
/**
 * Call back function for user link
 * 
 * @param mixed $matches
 * @return
 */
function replace_user_link_callback($matches)
{
    if (count($matches) < 2) {
        return null;
    }
    // if
    if (!logged_user()->isMemberOfOwnerCompany()) {
        $object = Users::findOne(array('conditions' => array('`id` = ? ', $matches[1])));
    } else {
        $object = Users::findOne(array('conditions' => array('`id` = ? ', $matches[1])));
    }
    // if
    if (!$object instanceof User) {
        return '<del>' . lang('invalid reference') . '</del>';
    } else {
        return '<a href="' . $object->getCardUrl() . '">' . $object->getObjectName() . '</a>';
    }
    // if
}
Esempio n. 9
0
 public static function isUserSubcomision($id)
 {
     if (Users::findOne(['dni' => $id, 'privilegio' => 2])) {
         return true;
     } else {
         return false;
     }
 }
 function do_share()
 {
     $share_data = array_var($_POST, 'share_data');
     if (is_array($share_data)) {
         $obj = get_object_by_manager_and_id(array_var($share_data, 'object_id'), array_var($share_data, 'object_manager'));
         $emails = array_var($_POST, 'emails');
         $companies = array_var($_POST, 'companiesId');
         if (!is_array($emails) || !count($emails)) {
             flash_error(lang('must specify recipients'));
             ajx_current("empty");
             return;
         }
         $people = array();
         foreach ($emails as $k => $email) {
             // Retrieve users to notify
             $lt_pos = strpos_utf($email, '<');
             if ($lt_pos !== FALSE) {
                 // only email address
                 $email = substr_utf($email, $lt_pos + 1);
                 $email = str_replace('>', '', $email);
             }
             if (trim($email) != '') {
                 $user = Users::findOne(array('conditions' => "`email` = '" . $email . "'"));
                 if (!$user instanceof User) {
                     // User not exists -> create one with minimum permissions
                     try {
                         DB::beginWork();
                         $user = $this->createMinimumUser($email, $companies[$k]);
                         DB::commit();
                     } catch (Exception $e) {
                         DB::rollback();
                     }
                 }
                 if ($user instanceof User) {
                     $people[] = $user;
                     $canWrite = array_var($share_data, 'allow_edit');
                     if ($canWrite && !$obj->canEdit($user) || !$obj->canView($user)) {
                         $this->setObjUserPermission($user, $obj, $canWrite);
                     }
                     $this->saveSharedObject($obj, $user);
                 }
             }
         }
         Notifier::shareObject($obj, $people);
         flash_success(lang("success sharing object"));
         ajx_current("back");
     }
 }
Esempio n. 11
0
 /**
  * Retrieves the currently authenticated user from the 
  * database and displays the form for editing their information.
  */
 public static function edit_form()
 {
     $user = Users::findOne($_SESSION['user']);
     View::make('user/edit.html', array('user' => $user));
 }
Esempio n. 12
0
 /**
  * Finds user by username
  *
  * @param  string      $username
  * @return static|null
  */
 public static function findByUsername($username)
 {
     $users = new Users();
     return $users->findOne(['email' => $username]);
 }