Exemplo n.º 1
0
 public function _index()
 {
     // Deny access if not logged in
     new Protect('ajax');
     $post = Input::post();
     $token = Token::ajaxCheck($post['token']);
     $data['success'] = FALSE;
     $data['errors'] = NULL;
     if (!empty($post['username'] && $token === TRUE)) {
         $msgs = Message::getMessages($post['username']);
         $data['success'] = TRUE;
         foreach ($msgs as $key => $value) {
             $msgs[$key]['time'] = date("d-M h:i A", $value['time']);
         }
         $data['msgs'] = $msgs;
         Message::read(User::getPublicUserId($post['username']));
         //TODO: Replace with function
         DB::updateIf('msg_notif', array('status' => 1), array('user_id' => User::getPublicUserId($post['username']), 'to_id' => Session::get('user_id')));
     } else {
         if (!$token) {
             $data['errors'][] = 'Security Token Missing';
         } else {
             $data['errors'][] = 'Username Required';
         }
     }
     if (!empty($data)) {
         return $data;
     } else {
         return FALSE;
     }
 }
Exemplo n.º 2
0
Arquivo: Group.php Projeto: ncube/edu
 public function acceptUser($id)
 {
     $data['user_id'] = User::getPublicUserId(Input::post('username'));
     $data['group_id'] = $id;
     DB::updateIf('group_user', array('status' => 1), $data);
     return TRUE;
 }
Exemplo n.º 3
0
Arquivo: Upload.php Projeto: ncube/edu
 public function profilePic($files)
 {
     $max_size = 300 * 1025;
     $path = 'data/images/profile/';
     if (!empty($files["uploaded_file"]) && $files['uploaded_file']['error'] == 0) {
         $filename = basename($files['uploaded_file']['name']);
         $ext = substr($filename, strrpos($filename, '.') + 1);
         $filename = md5(mt_rand());
         $finfo = finfo_open(FILEINFO_MIME_TYPE);
         $type = finfo_file($finfo, $files['uploaded_file']['tmp_name']);
         $allowed_ext = array('jpg', 'JPG');
         $allowed_type = array('image/jpeg');
         if (in_array($ext, $allowed_ext) && in_array($type, $allowed_type) && $files["uploaded_file"]["size"] < $max_size) {
             $newname = $path . $filename . '.' . $ext;
             DB::updateIf('user', array('profile_pic' => $filename), array('user_id' => Session::get('user_id')));
             if (!file_exists($newname)) {
                 if (move_uploaded_file($files['uploaded_file']['tmp_name'], $newname)) {
                     echo "Successfully Uploaded!";
                 } else {
                     echo "Error: A problem occurred during file upload!";
                 }
             } else {
                 echo "Error: File " . $files["uploaded_file"]["name"] . " already exists";
             }
         } else {
             echo "Error: Only .jpg images under 300Kb are accepted for upload";
         }
     } else {
         echo "Error: No file uploaded";
     }
 }
Exemplo n.º 4
0
 public function countQuestionViews($id)
 {
     $count = DB::fetch(array('question' => ['views']), array('q_id' => $id))[0];
     if (!empty($count)) {
         $count = $count->views;
         $count++;
         DB::updateIf('question', array('views' => $count), array('q_id' => $id));
         return TRUE;
     } else {
         return FALSE;
     }
 }
Exemplo n.º 5
0
Arquivo: Notif.php Projeto: ncube/edu
 public function raiseMsgNotif($to_id)
 {
     if (!empty($to_id)) {
         #code...
     } else {
         return FALSE;
     }
     $user_id = Session::get('user_id');
     // Check if exists
     $count = DB::fetchCount('msg_notif', array('user_id' => $user_id, 'to_id' => $to_id));
     if ($count === 0) {
         DB::insert('msg_notif', array('user_id' => $user_id, 'to_id' => $to_id, 'time' => time()));
         return TRUE;
     } else {
         DB::updateIf('msg_notif', array('status' => 0, 'time' => time()), array('user_id' => $user_id, 'to_id' => $to_id));
         return TRUE;
     }
 }
Exemplo n.º 6
0
 public function read($from_id)
 {
     DB::updateIf('msg', array('status' => 1), array('from_id' => $from_id, 'to_id' => Session::get('user_id')));
     return TRUE;
 }
Exemplo n.º 7
0
Arquivo: User.php Projeto: ncube/edu
 public function accept($post)
 {
     $user_id = User::getPublicUserId($post['username']);
     DB::updateIf('request', array('status' => 1), array('user_id' => $user_id));
     return 'Accepted';
 }