Exemple #1
0
 public function uploadCalendar()
 {
     //$data = json_decode(file_get_contents('php://input'), true);
     $data = $_POST;
     $data['username'] = user_decrypt($data['username']);
     $file = $_FILES['file'];
     $return['error'] = 0;
     $return['value'] = "Uploaded successfully";
     $weights = array();
     if (isset($data['weights'])) {
         //print_r($data['weights']);
         //file_put_contents('aaa.txt', print_r(json_decode($data['weights'],true),true),FILE_APPEND | LOCK_EX);
         foreach (json_decode($data['weights'], true) as $sw) {
             $pat = '/' . str_replace(' ', '.*', $sw['string']) . '/i';
             $weights[] = array('pattern' => $pat, 'weight' => $sw['weight']);
         }
     }
     if (getUserUID($data['username'])) {
         if ($data['calname'] == "UNSW") {
             if (isset($file)) {
                 if (!$this->unsw_addToDatabase($data['username'], $data['calname'], $file['tmp_name'], $weights)) {
                     $return['error'] = -3;
                     $return['value'] = "File couldn't convert, broken metadata";
                 }
             } else {
                 $return['error'] = -3;
                 $return['value'] = "Invalid file type";
             }
         } else {
             //Do nothing for now
         }
     } else {
         $return['error'] = -1;
         $return['value'] = "Invalid username";
     }
     $jsonString = json_encode($return);
     echo $jsonString;
 }
Exemple #2
0
function addGroup($username, $groupName)
{
    $CI = get_instance();
    $uid = getUserUID($username);
    $existing = memberOf($username);
    foreach ($existing as $g) {
        if ($g['owner'] == $uid && $groupName == $g['name']) {
            //cant OWN 2 groups with same name
            return -1;
        }
    }
    $ins = array('name' => $groupName, 'owner' => $uid);
    $CI->db->insert('Groups', $ins);
    $gid = $CI->db->insert_id();
    $ins = array('gid' => $gid, 'uid' => $uid, 'accepted' => 'Y');
    $CI->db->insert('GroupMemberships', $ins);
    return $gid;
}
Exemple #3
0
 public function signup()
 {
     //Gather data
     $data = json_decode(file_get_contents('php://input'), true);
     $return['error'] = 0;
     $return['value'] = "Successfully signed up";
     //Validate inputs
     /*$result = $this->checkEmpty($data['username']);
     		$result2 = $this->checkEmpty($data['password']);
             $result3 = $this->checkEmpty($data['passwordcheck']);*/
     $result = $this->checkInput($data, array('username', 'password', 'passwordcheck'));
     if ($result == '') {
         //Check the login passwords are the same
         $result4 = $this->checkSame($data['password'], $data['passwordcheck']);
         if ($result4) {
             //Check if user exists
             $uid = getUserUID($data['username']);
             if ($uid == null) {
                 //Salt the password
                 $salt = $this->generateSalt();
                 $saltedPw = crypt($data['password'], $salt);
                 //Insert User
                 insertUser($data['username'], $saltedPw, $salt);
             } else {
                 $return['error'] = -3;
                 $return['value'] = "This username already exists, please choose another";
             }
         } else {
             $return['error'] = -2;
             $return['value'] = "The passwords do not match. Please try again";
         }
     } else {
         $return['error'] = -1;
         $return['value'] = $result;
     }
     //Returns boolean string 'true' or 'false' whether signup was successful
     $jsonstring = json_encode($return);
     echo $jsonstring;
 }
Exemple #4
0
 public function json_GetEvents()
 {
     $data = json_decode(file_get_contents('php://input'), true);
     $check = $this->checkInput($data, array('username', 'calname', 'month', 'year'));
     $data['username'] = user_decrypt($data['username']);
     if ($check == '') {
         if (getUserUID($data['username']) <= 0) {
             $return['error'] = -2;
             $return['value'] = "Invalid username";
             $return['passed'] = $data;
         } else {
             $return = getEventsForAMonth($data['username'], $data['calname'], $data['month'], $data['year']);
             foreach ($return as &$r) {
                 $r['title'] = $r['name'];
                 $r['id'] = $r['eid'];
             }
         }
     } else {
         $return['error'] = -1;
         $return['value'] = $check;
     }
     $jsonstring = json_encode($return);
     echo $jsonstring;
 }