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']])); } } } }
/** * @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 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; } } }
/** * Get the value of a given cookie * @param string $key Name of cookie to be retrieved * @param string $default * @return mixed */ public function get($key, $default = "") { if (!is_null($value = RequestMethods::cookie($key))) { return $this->parse($value); } return $default; }
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 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 function packages() { $view = $this->getActionView(); $states = State::all(); $view->set('states', $states); $source = RequestMethods::get('source'); $source_state = State::first(array('id = ?' => $source)); $dest = RequestMethods::get('dest'); $dest_state = State::first(array('id = ?' => $dest)); $month = RequestMethods::get('month'); $year = RequestMethods::get('year'); $page = RequestMethods::get('page', 1); $limit = 9; if (RequestMethods::get('source')) { $count = Package::count(array('source Like ?' => $source, 'destination Like ?' => $dest, 'month = ?' => $month, 'year = ?' => $year)); $total_pages = $count / 9 + 1; for ($i = 1; $i <= $total_pages; $i++) { $pages[$i] = $i; } $packages = Package::all(array('source Like ?' => $source, 'destination Like ?' => $dest, 'month = ?' => $month, 'year = ?' => $year, 'live = ?' => 1), array("*"), null, null, $limit, $page); $view->set('n', 'http://planyourtours.io/travels/packages?source=' . $source . '&dest=' . $dest . '&type=Group&month=' . $month . '&year=' . $year . '&page=')->set('source', $source_state)->set('dest', $dest_state)->set('month', $month)->set('year', $year); } else { $count = Package::count(); $total_pages = $count / 9 + 1; for ($i = 1; $i <= $total_pages; $i++) { $pages[$i] = $i; } $packages = Package::all(array('live = ?' => 1), array("*"), null, null, $limit, $page); $view->set('n', 'http://planyourtours.io/travels/packages?&page='); } if (!empty($packages)) { $view->set('packages', $packages)->set('pages', $pages); } }
public static function page($opts = array()) { $limit = RequestMethods::get("limit", 10); $page = RequestMethods::get("page", 1); $count = $opts["model"]::count($opts["where"]); return array("limit" => $limit, "page" => $page, "count" => $count); }
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 index() { $this->getLayoutView()->set("seo", Framework\Registry::get("seo")); $view = $this->getActionView(); $limit = RequestMethods::get("limit", 10); $page = RequestMethods::get("page", 1); $items = Campaign::all(array("live = ?" => true), array("id", "live", "image", "title", "description"), "created", "desc", $limit, $page); $count = Campaign::count(array("live = ?" => true)); $view->set("items", $items)->set("count", $count)->set("limit", $limit)->set("page", $page); }
/** * Makes GET request to the URL and return the results to the templateโs $_text array, * where it will be rendered to the final template output * @param type $tree * @param type $content * @return type */ protected function _partial($tree, $content) { $address = trim($tree["raw"], " /"); if (StringMethods::indexOf($address, "http") != 0) { $host = RequestMethods::server("HTTP_HOST"); $address = "http://{$host}/{$address}"; } $request = new Request(); $response = addslashes(trim($request->get($address))); return "\$_text[] = \"{$response}\";"; }
/** * @before _secure, _admin */ public function all() { $this->seo(array("title" => "View Users Stats", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView())); $view = $this->getActionView(); $page = RequestMethods::get("page", 1); $limit = RequestMethods::get("limit", 10); $orderBy = RequestMethods::get("orderBy", "created"); $users = \User::all(array(), array("*"), $orderBy, "desc", $limit, $page); $total = \User::count(); $view->set(array("count" => $total, "results" => $users, "limit" => $limit, "page" => (int) $page)); }
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); }
/** * @before _secure, changeLayout, _admin */ public function participants() { $this->seo(array("title" => "Game Participants", "view" => $this->getLayoutView())); $view = $this->getActionView(); $limit = RequestMethods::get("limit", 10); $page = RequestMethods::get("page", 1); $participants = Participant::all(array(), array("*"), "created", "desc", $limit, $page); $count = Participant::count(); $view->set("participants", $participants); $view->set("count", $count); $view->set("limit", $limit); $view->set("page", $page); }
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); } }
/** * Make GET request to given URL and place the results * in the template file * @param array $tree Node from the template tree * @param mixed $content Content of node * @return string String to be included in template */ protected function _partial($tree, $content) { $address = trim($tree["raw"], " /"); // Convert a relative URl to an absolute URL if (StringMethods::indexOf($address, "http") != 0) { $host = RequestMethods::server("HTTP_HOST"); $address = "http://{$host}/{$address}"; } // Make GET request to URL and return results to // template $_text array $request = new Request(); $response = addslashes(trim($request->get($address))); return "\$_text[] = \"{$response}\";"; }
/** * @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); }
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; }
/** * Hook for determining if the request was XHR * also works as a direct method call * @protected */ public function _ajax() { // If request was XHR $request = RequestMethods::server('HTTP_X_REQUESTED_WITH'); if (isset($request) && $request === 'XMLHttpRequest') { $this->ajax = true; return true; } // If request was not manage the correct response // If ajax test was via @before hook $caller = list(, $caller) = debug_backtrace(false); if ($caller[1]['function'] == 'Framework\\{closure}' && $caller[1]['args'][1] == '@before') { throw new \Exception("NOT AJAX", 1); } else { // If ajax test was simple method call return false; } }
/** * 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, _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); }
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; }
public function getBooks() { $this->isApiNavigation = true; $arrayWhere = array(); $arrayGet = array(); $arrayGet['isbn'] = \Framework\RequestMethods::get('isbn', true, null); $arrayGet['title'] = \Framework\RequestMethods::get('title', true, null); $arrayGet['author.last_name'] = \Framework\RequestMethods::get('author', true, null); //$arrayGet['author.first_name'] = \Framework\RequestMethods::get('author', true, null); foreach ($arrayGet as $k => $v) { if (!is_null($v)) { $arrayWhere[$k] = array('%' . $v . '%', 'LIKE'); } } $rating = \Framework\RequestMethods::get('rating', true, null); if (!is_null($rating) && is_numeric($rating)) { $arrayWhere['rating'] = array($rating, '>='); } $year = \Framework\RequestMethods::get('year', true, null); if (!is_null($rating) && is_numeric($rating)) { $arrayWhere['year'] = $year; } $start_date = strtotime(\Framework\RequestMethods::get('start_date', true, false)); $end_date = strtotime(\Framework\RequestMethods::get('end_date', true, false)); if ($start_date) { $arrayWhere['book.created'] = array('FROM_UNIXTIME(' . $start_date . ')', '>=', true); } if ($end_date) { $arrayWhere['book.created'] = array('FROM_UNIXTIME(' . $end_date . ')', '<=', true); } $books = Book::getAllForApi($arrayWhere); if (!is_null($books)) { $this->actionView->set('books', $books); } else { \Framework\Registry::get('httpRequest')->setResponseCode(\Framework\HttpRequest::HTTP_RESPONSE_NO_CONTENT); } }
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); } }
/** * Find the Performance of Affiliates|Advertisers of an organization * @param object $org \Organization * @param string $type Type of user * @return [type] [description] */ public static function perf($org, $type, $opts = []) { $start = $opts['start'] ?? RequestMethods::get('start', date('Y-m-d', strtotime("-5 day"))); $end = $opts['end'] ?? RequestMethods::get('end', date('Y-m-d', strtotime("-1 day"))); switch ($type) { case 'publisher': $perfFields = $opts['fields'] ?? ['clicks', 'impressions', 'conversions', 'revenue', 'created']; $meta = $opts['meta'] ?? false; if ($meta) { $perfFields[] = 'meta'; } $publishers = $opts['publishers'] ?? $org->users($type); $pubPerf = Perf::all(['user_id' => ['$in' => $publishers], 'created' => Db::dateQuery($start, $end)], $perfFields, 'created', 'asc'); $pubPerf = Perf::objectArr($pubPerf, $perfFields); return $pubPerf; case 'advertiser': $advertisers = $opts['advertisers'] ?? $org->users($type); $fields = $opts['fields'] ?? ['revenue', 'created']; $advertPerf = Perf::all(['user_id' => ['$in' => $advertisers], 'created' => Db::dateQuery($start, $end)], $fields, 'created', 'asc'); $advertPerf = Perf::objectArr($advertPerf, $fields); return $advertPerf; } return []; }
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 _secure */ public function ping() { $this->JSONview(); $view = $this->getActionView(); $url = RequestMethods::get("link"); if (!$url) { $this->redirect("/404"); } $count = 0; $stats = Registry::get("MongoDB")->ping_stats; $ping = Registry::get("MongoDB")->ping; $record = $ping->findOne(array('url' => $url, 'user_id' => (int) $this->user->id)); if (!$record) { $this->redirect("/404"); } $count = $stats->count(array('ping_id' => $record['_id'])); $cursor = $stats->find(array('ping_id' => $record['_id'])); $cursor->sort(['created' => -1]); $cursor->limit(1); foreach ($cursor as $c) { $live = $c['latency']; } $count += $count; $view->set("count", $count)->set("status", $live === false ? "down" : "up")->set("success", true); }