public function forgotpassword() { $this->seo(array("title" => "Register", "view" => $this->getLayoutView())); $view = $this->getActionView(); if (RequestMethods::post("action") == "change") { $token = RequestMethods::post("token"); $id = base64_decode($token); $user = User::first(array("id = ?" => $id)); if (RequestMethods::post("password") == RequestMethods::post("cpassword")) { $user->password = sha1(RequestMethods::post("password")); $user->save(); $this->session($user); $this->redirect("/member"); } else { $view->set("message", 'Password Does not match'); } } if (RequestMethods::get("action") == "reset") { $token = RequestMethods::get("token"); $id = base64_decode($token); $exist = User::first(array("id = ?" => $id), array("id")); if ($exist) { $view->set("token", $token); } else { $view->set("message", 'Something Went Wrong please contact admin'); } } }
public function login() { if (RequestMethods::post('login')) { $email = RequestMethods::post('email'); $password = RequestMethods::post('password'); $view = $this->getActionView(); $error = false; if (empty($email)) { $view->set('email_error', 'Email is not provided'); $error = true; } if (empty($password)) { $view->set('password_error', 'Password is not provided'); $error = true; } if (!$error) { $user = User::first(array('email=?' => $email, 'password=?' => $password, 'live=?' => true, 'deleted=?' => false)); if (!empty($user)) { $session = Registry::get('session'); $session->set('user', serialize($user)); header("Location: /users/profile.html"); exit; } else { $view->set('password_error', 'Email address and/or password are incorrect'); } exit; } } }
/** * @before _secure, memberLayout */ public function edit($id) { if (!$id) { $this->redirect("/member"); } $website = Website::first(array("id = ?" => $id)); $this->_authority($website); $this->seo(array("title" => "Edit your website", "view" => $this->getLayoutView())); $view = $this->getActionView(); if (RequestMethods::post('action') == 'editWebsite') { $title = RequestMethods::post('name'); $url = RequestMethods::post('url'); $url = preg_replace('/^https?:\\/\\//', '', $url); $url = rtrim($url, "/"); $exists = Website::first(array('url = ?' => $url)); if ($exists) { $view->set("message", "Website already exists"); } else { $website->url = $url; $website->title = $title; $website->save(); $collection = Registry::get("MongoDB")->selectCollection("website"); $record = $collection->findOne(array('website_id' => (int) $website->id)); if (isset($record)) { $collection->update(array('website_id' => (int) $website->id), array('$set' => array("title" => $website->title, "url" => $website->url))); } $view->set("message", "Website Changed Successfully"); } } $view->set('website', $website); }
public function index() { $view = $this->getActionView(); $error = NULL; if (RequestMethods::post("postit")) { $error = $this->postit(); } if (RequestMethods::post("user_register")) { $error = $this->register(); } if (RequestMethods::post("user_login")) { $error = $this->login(); } if (!empty($error)) { $view->set("error", $error); } if (RequestMethods::post("search")) { $search = RequestMethods::post("search"); } else { $search = "web"; } $posts = $this->search($search); $view->set("search", $search); $view->set("posts", $posts); }
public static function saveRecord($user, $organization) { $slots = \Shared\Services\Doctor::slots($user); foreach (RequestMethods::post("slot") as $key => $value) { if (isset($value["hlimit"])) { $d = ['capacity' => $value['hlimit'], 'day' => $key]; if (isset($slots[$key])) { // if no slots for the day $day_slots = $slots[$key]; $s = $day_slots[0]; $s->start = $value["start-1"]; $s->end = $value["end-1"]; $s->capacity = $value["hlimit"]; $result = $s->validate() ? $s->save() : $s->errors; if (isset($day_slots[1])) { // check if second slot present $s = $day_slots[1]; $s->start = $value['start-2']; $s->end = $value['end-2']; $s->capacity = $value['hlimit']; $result = $s->validate() ? $s->save() : $s->errors; } else { self::_save($user, $organization, array_merge($d, ['start' => $value['start-2'], 'end' => $value['end-2']])); } } else { self::_save($user, $organization, array_merge($d, ['start' => $value['start-1'], 'end' => $value['end-1']])); self::_save($user, $organization, array_merge($d, ['start' => $value['start-2'], 'end' => $value['end-2']])); } } } }
public static function create(\Organization $org) { $msg = 'Added STMP details!!'; $search = ['prop' => 'orgSmtp', 'propid' => $org->_id]; $meta = Meta::first($search); if (!$meta) { $meta = new Meta($search); } $fields = ['server', 'username', 'password', 'email', 'from', 'email', 'security', 'port']; $value = []; foreach ($fields as $key) { $v = RequestMethods::post($key); if (!$v) { return 'Please Fill the Required Fields'; } $value[$key] = $v; } $value['password'] = Utils::encrypt($value['password'], $org->_id); $meta->value = $value; if ($meta->validate()) { $meta->save(); } else { $msg = 'Fill all required values'; } return $msg; }
public static function createOrg($opts) { $organization = \Organization::saveRecord(null, array("name" => $opts['user']->name)); $centre = new \Centre(array("user_id" => $opts['user']->id, "organization_id" => $organization->id, "type" => "clinic", "department" => json_encode(RequestMethods::post("department", array("Clinic"))), "phone" => RequestMethods::post("org_phone", ""), "location_id" => $opts['location']->id)); $centre->save(); $member = new \Member(array("user_id" => $opts['user']->id, "centre_id" => $centre->id, "organization_id" => $organization->id, "designation" => "admin", "image" => "", "live" => 1)); $member->save(); return $organization; }
/** * @before _secure, _school */ public function createfee() { $this->setSEO(array("title" => "Fee | School")); $view = $this->getActionView(); $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title")); $view->set("grades", $grades); if (RequestMethods::post("action") == "createFee") { } }
public function add() { $user = $this->getUser(); if (RequestMethods::post("share")) { $message = new Message(array("body" => RequestMethods::post("body"), "message" => RequestMethods::post("message"), "user" => $user['id'])); if ($message->validate()) { $message->save(); $this->redirect('/'); } } }
/** * @before _secure, changeLayout, _admin */ public function fbapps() { $this->seo(array("title" => "FBApps", "view" => $this->getLayoutView())); $view = $this->getActionView(); if (RequestMethods::post("action") == "fbapps") { $fbapp = new Meta(array("user_id" => $this->user->id, "property" => "fbapp", "value" => RequestMethods::post("fbapp"))); $fbapp->save(); $view->set("message", "FBApp Added Successfully"); } $fbapps = Meta::all(array("property=?" => "fbapp")); $view->set("fbapps", $fbapps); }
public function reg() { $view = $this->getActionView(); if (RequestMethods::post('register')) { $error = $this->register(); } if (RequestMethods::post('login')) { $error = $this->login(); } if (isset($error)) { $view->set('error', $error); } }
private static function _save($location, $opts) { $location->street = RequestMethods::post("street"); $location->area_id = RequestMethods::post("area_id"); $location->city_id = RequestMethods::post("city_id"); if (!isset($opts['validate'])) { $location->save(); } else { if ($location->validate()) { $location->save(); } else { return $location->errors; } } return $location; }
/** * @before _secure, _school */ public function edit($grade_id) { $this->setSEO(array("title" => "School | Edit Class")); $view = $this->getActionView(); $grade = \Grade::first(array("id = ?" => $grade_id)); if (!$grade || $grade->organization_id != $this->organization->id) { self::redirect("/school"); } if (RequestMethods::post("action") == "editGrade") { $grade->title = RequestMethods::post("title"); $grade->description = RequestMethods::post("description"); $grade->save(); $view->set("success", "Grade edited successfully!"); } $view->set("grade", $grade); }
/** * @before _secure, _school */ public function edit($subject_id, $grade_id) { $course = \Course::first(array("id = ?" => $subject_id)); if (!$course || $course->organization_id != $this->organization->id || $course->grade_id != $grade_id) { self::redirect("/school"); } $grade = \Grade::first(array("id = ?" => $grade_id), array("id", "title", "organization_id")); $this->setSEO(array("title" => "School | Manage Subjects (Courses)")); $view = $this->getActionView(); if (RequestMethods::post("action") == "editSubject") { $course->title = RequestMethods::post("title"); $course->description = RequestMethods::post("description"); $course->save(); $view->set("success", "Subject Updated successfully!!"); } $view->set("course", $course); $view->set("grade", $grade); }
/** * Adds New AD Categories by checking if that category already exists in * the database to prevent duplicate */ public static function addNew(&$categories, $org, $newCat = []) { $result = []; ArrayMethods::copy($categories, $result); $cat = RequestMethods::post("category") ?? $newCat; foreach ($cat as $c) { $found = self::first(['name' => strtolower($c), 'org_id' => $org->_id], ['_id', 'name']); // remove those which are found if ($found) { unset($categories[$found->getMongoID()]); continue; } $category = new self(['name' => $c, 'org_id' => $org->_id]); $category->save(); $result[$category->_id] = $category; } return $result; }
/** * @before _secure, memberLayout */ public function edit() { $this->seo(array("title" => "Ping | Edit", "view" => $this->getLayoutView())); $view = $this->getActionView(); $url = RequestMethods::get("link"); $ping = Registry::get('MongoDB')->ping; $search = ['url' => $url, 'user_id' => (int) $this->user->id]; $record = $ping->findOne($search); if (!$record) { $this->redirect('/member/index'); } if (RequestMethods::post('title')) { $ping->update($search, array('$set' => array("title" => RequestMethods::post('title'), "interval" => RequestMethods::post('interval')))); $record = $ping->findOne($search); $view->set("success", "Updated!!"); } $view->set('title', $record['title'])->set('url', $record['url'])->set('interval', $record['interval']); }
/** * @before _secure, _school */ public function misc() { $this->JSONView(); $view = $this->getActionView(); if (RequestMethods::post("action") == "process") { $opts = RequestMethods::post("opts"); $query = $opts["query"]; $where = array(); foreach ($query as $q) { $where[$q["where"]] = $q["value"]; } $fields = isset($opts['fields']) ? $opts['fields'] : array("*"); $check = $opts["model"]::all($where, $fields); if ($check) { $view->set("results", $check); } else { $view->set("error", true); } } }
public function myaccount() { $view = $this->getActionView(); $states = State::all(); $countries = Country::all(); $view->set('states', $states)->set('countries', $countries); if (RequestMethods::post('update')) { $user = User::first(array('id = ?' => $this->user->id)); $user->full_name = RequestMethods::post('full_name'); $user->country = RequestMethods::post('country'); $user->state = RequestMethods::post('state'); $user->pincode = RequestMethods::post('pin'); $user->address = RequestMethods::post('address'); if ($user->validate) { $user->save(); } else { echo "validation not good"; } } }
public function submit($assignment) { $user = Registry::get("session")->get("user"); $sub = Registry::get("MongoDB")->submission; $maxSize = "6291456"; $return = array(); $return["maxSize"] = $maxSize; $return["assignment"] = $assignment; $allowed = strtotime($assignment->deadline); $today = date('Y-m-d'); if ($today > $allowed) { $return["error"] = "Last Date of submission is over"; return $return; } $where = array("user_id" => (int) $user, "assignment_id" => (int) $assignment->id); $submission = $sub->findOne($where); if ($submission) { $return["success"] = "Assignment already submitted! Your response will be updated"; } if (RequestMethods::post("action") == "submitAssignment") { if (RequestMethods::post("maxSize") != $maxSize) { $return["success"] = "Invalid Response"; return $return; } $response = $this->_upload("response", array("type" => "assignments", "mimes" => "png|jpe?g|bmp|gif")); if (!$response) { $return["success"] = "File Upload failed!"; return $return; } if (!$submission) { $sub->insert(array("user_id" => (int) $user, "assignment_id" => (int) $assignment->id, "course_id" => (int) $assignment->course_id, "response" => $response, "grade" => null, "remarks" => null, "modified" => new \MongoDate(), "created" => new \MongoDate(), "live" => true)); } else { $sub->update($where, array('$set' => array('response' => $response))); unlink(APP_PATH . "/public/assets/uploads/assignments/" . $submission['response']); } $return["success"] = "You have successfully submitted the assignment!"; } return $return; }
/** * @before _secure, memberLayout */ public function profile() { $this->seo(array("title" => "Profile", "view" => $this->getLayoutView())); $view = $this->getActionView(); $user = User::first(array("id = ?" => $this->user->id)); switch (RequestMethods::post("action")) { case 'saveUser': $user->phone = RequestMethods::post('phone'); $user->name = RequestMethods::post('name'); $user->save(); $view->set("success", true); break; case 'changePass': if (sha1(RequestMethods::post('oldpass')) == $user->password) { $user->password = sha1(RequestMethods::post('newpass')); $user->save(); $view->set("success", true); } break; } $this->setUser($user); }
public function myaccount($s = "user") { $view = $this->getActionView(); if (RequestMethods::post('delete')) { $del = Post::first(array('id = ?' => RequestMethods::post('id'))); $del->delete(); } if (RequestMethods::post('block')) { $block = User::first(array("id = ?" => RequestMethods::post('id'))); $block->live = 0; $block->save(); } if (RequestMethods::post('unblock')) { $block = User::first(array("id = ?" => RequestMethods::post('id'))); $block->live = 1; $block->save(); } if (isset($this->_user)) { $admin = User::first(array("admin = ?" => '1', "id = ?" => $this->user->id)); if (!empty($admin)) { if ($s != 'post') { $admin_table = $s::all(); } if ($s == 'post') { $database = Registry::get("database"); $conn = $database->initialize(); $admin_table = $conn->query()->from('posts')->join("users", "posts.from_user = users.id")->all(); } $view->set("admin_table", $admin_table); } else { $posts = Post::all(array("from_user = ?" => $this->user->id)); $view->set("posts", $posts); } $view->set("admin", $admin)->set('table', $s); } }
public static function customFields($user, $org) { $afields = \Meta::search('customField', $org); if (count($afields) > 0) { $meta = $user->meta ?? []; $extraFields = []; foreach ($afields as $value) { $key = $value['name']; $type = $value['type']; $message = $value['label'] . " is required!!"; switch ($type) { case 'file': $v = Utils::media($key, 'upload', ['extension' => 'jpe?g|gif|bmp|png|tif|pdf']); if (!$v) { $message = "Please Upload a valid image or pdf file"; } break; case 'text': $v = RequestMethods::post($key); break; case 'date': $d = RequestMethods::post($key, date('Y-m-d')); $v = Db::convertType($d, 'date'); break; default: $v = ''; break; } if (!$v && $value['required']) { return ["message" => $message, "success" => false]; } $extraFields[$key] = $v; } $meta['afields'] = $extraFields; $user->meta = $meta; } $user->save(); return ["success" => true]; }
/** * @before _session */ public function verify($encrypt) { $this->seo(array("title" => "Thanks for Registering", "view" => $this->getLayoutView())); $view = $this->getActionView(); if ($encrypt) { $email = base64_decode($encrypt); $user = User::first(array("email = ?" => $email)); if ($user) { $view->set("message", "Please create a password"); } else { $this->redirect("/login.html"); } } if (RequestMethods::post("action") == "setpass") { if (RequestMethods::post("password") == RequestMethods::post("rpassword")) { $user->password = sha1(RequestMethods::post("password")); $user->live = 1; $user->save(); $this->setUser($user); $this->session(); $this->redirect("/vendor/profile"); } else { $view->set("message", "Password doesnot match"); } } }
/** * @return string|array Array on DB validation errors, else string messages */ private function _saveSerp($keyword, $link) { $keyword = RequestMethods::post("keyword"); $link = RequestMethods::post("link"); $regex = Shared\Markup::websiteRegex(); if (!preg_match("/^{$regex}\$/", $link)) { return "Invalid URL"; } $serp = Keyword::first(array("link = ?" => $link, "user_id = ?" => $this->user->id, "keyword = ?" => $keyword, "serp = ?" => true)); if ($serp) { return "SERP Already Registered"; } $serp = new Keyword(array("link" => $link, "user_id" => $this->user->id, "keyword" => $keyword, "serp" => true)); if ($serp->validate()) { $serp->save(); return "Serp Action saved succesfully!!"; } else { $errors = $keyword->errors; return $errors; } }
/** * @before _secure, _vendor */ public function update($id) { $this->seo(array("title" => "Update Runner Profile", "view" => $this->getLayoutView())); $view = $this->getActionView(); $runner = Member::first(array("id = ?" => $id)); $ruser = User::first(array("id = ?" => $runner->user_id)); if (RequestMethods::post("action") == "runner") { $img = $this->_upload('image', "images", array('extensions' => 'jpe?g|gif|png|bmp', 'filename' => $runner->image)); if ($img) { $runner->image = $img; $runner->save(); } $save = true; $ruser->name = RequestMethods::post("name", ""); $email = RequestMethods::post("email", ""); $phone = RequestMethods::post("phone", ""); if ($email && $email != $ruser->email) { $exist = User::first(array("email = ?" => $email)); if ($exist) { $view->set("success", "Email already exists"); $save = false; } else { $ruser->email = $email; } } if ($phone && $phone != $ruser->phone) { $exist = User::first(array("phone = ?" => $phone)); if ($exist) { $view->set("success", "Phone already exists"); $save = false; } else { $ruser->phone = $phone; } } $ruser->gender = RequestMethods::post("gender"); $ruser->birthday = RequestMethods::post("birthday"); if ($save) { $ruser->save(); $view->set("success", "Runner Updated Successfully!!"); } } $view->set("runner", $runner); $view->set("ruser", $ruser); }
/** * Updates any data provide with model and id * * @before _secure, _admin * @param type $model the model object to be updated * @param type $id the id of object */ public function update($model = NULL, $id = NULL) { $this->seo(array("title" => "Update", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView())); $view = $this->getActionView(); $object = $model::first(array("id = ?" => $id)); $vars = $object->columns; $array = array(); foreach ($vars as $key => $value) { array_push($array, $key); $vars[$key] = htmlentities($object->{$key}); } if (RequestMethods::post("action") == "update") { foreach ($array as $field) { $object->{$field} = RequestMethods::post($field, $vars[$field]); $vars[$field] = htmlentities($object->{$field}); } $object->save(); $view->set("success", true); } $view->set(array("vars" => $vars, "array" => $array, "model" => $model, "id" => $id)); }
/** * @before _secure */ public function profile() { $this->seo(array("title" => "Profile", "view" => $this->getLayoutView())); $view = $this->getActionView(); $user = $this->user; $view->set("errors", array()); if (RequestMethods::post("action") == "saveUser") { $user->name = RequestMethods::post("name"); $user->phone = RequestMethods::post("phone"); $password = RequestMethods::post("password"); if (!empty($password)) { $user->password = sha1($password); } $user->save(); $this->setUser($user); $view->set("success", "Info updated!!"); } $locations = Location::all(array("user_id = ?" => $this->user->id), array("*"), "created", "desc"); $family = Shared\Services\Patient::findFamily($this->user); $flocations = Shared\Services\Patient::familyLoc($family); if (RequestMethods::post("action") == "saveLocation") { $location_id = RequestMethods::post("location_id"); $location = $locations[$location_id]; $l = \Location::saveRecord(null, $location, array("validate" => true)); if (is_array($l)) { $view->set("success", "Fix the following errors")->set("errors", $l); } else { $locations[$location_id] = $l; $view->set("success", "Updated Location"); } } if (RequestMethods::post("addLocation")) { $user_id = (int) RequestMethods::post("user_id", $this->user->id); if ((int) $this->user->id == $user_id) { $u = $this->user; } else { $u = ArrayMethods::toObject(['id' => $family[$user_id]->user_id]); } $location = \Location::saveRecord($u, null, array("validate" => true)); if (is_array($location)) { $view->set("success", "Fix the following errors")->set("errors", $location); } else { $view->set("success", "Added New Location"); $arr = array($location->id => $location); $locations = array_merge($locations, $arr); } } $view->set("locations", $locations)->set("family", $family)->set("flocations", $flocations); }
/** * @before _secure, _student */ public function performance($course_id = null) { $this->JSONView(); $view = $this->getActionView(); $course_id = RequestMethods::post("course", $course_id); $courses = StudentService::$_courses; if (!$course_id) { $course = array_shift($courses); } else { $course = $courses[$course_id]; } $service = new StudentService(); $find = $service->performance($course); $view->set("performance", $find['performance'])->set("monthly", $find['monthly']); }
/** * Assign which course will the teacher will teach * @before _secure, _school */ public function assign($user_id) { $usr = \User::first(array("id = ?" => $user_id), array("id")); if (!$usr) { self::redirect("/school"); } $this->setSEO(array("title" => "Assign Teachers for different subjects")); $view = $this->getActionView(); $grades = \Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title")); $view->set("grades", $grades); if (RequestMethods::post("action") == "assignTeacher") { $teaches = $this->reArray($_POST); foreach ($teaches as $t) { if (!empty($t["section"]) || !empty($t["course"])) { continue; } $teach = new \Teach(array("grade_id" => $t["grade"], "classroom_id" => $t["section"], "course_id" => $t["course"], "user_id" => $usr->id, "organization_id" => $this->organization->id)); if ($teach->validate()) { $teach->save(); } } $view->set("success", "Subjects assigned!!"); } $teaches = Teach::all(array("user_id = ?" => $usr->id, "live = ?" => true)); $view->set("teaches", $teaches); }
protected function _process($opts) { $trigger_title = RequestMethods::post("trigger"); $action_title = RequestMethods::post("action"); $trigger_val = RequestMethods::post("trigger_val"); $action_val = RequestMethods::post("action_val"); $this->_save(array('trigger' => array('title' => $trigger_title, 'meta' => $trigger_val, 'saved' => $opts['trigger']), 'action' => array('title' => $action_title, 'inputs' => $action_val, 'saved' => $opts['action']), 'website_id' => $opts['website_id'])); }