Esempio n. 1
0
 public function changeEmail($email)
 {
     if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $link = AdminUtility::getDefaultDBConnection();
         $query = "update admins set email='" . $email . "' where username='******'";
         mysqli_query($link, $query);
         //Log error
         AdminUtility::logMySQLError($link);
         //Reload data
         $this->adminInfo = $this->getAdminData();
     } else {
         throw new Exception("Invalid mail");
     }
 }
Esempio n. 2
0
/**
 * Resets admin password, requires AdminUtility to be included 
 * @param type $id
 * @param type $newPassword
 */
function resetAdminPassword($id, $newPassword)
{
    //Check password
    $link = AdminUtility::getDefaultDBConnection();
    $pwd = crypt($newPassword);
    $query = "update admins set password='******' where username='******'";
    mysqli_query($link, $query);
    //Log error
    AdminUtility::logMySQLError($link);
}
Esempio n. 3
0
 function activateUsers(array $regno)
 {
     $link = AdminUtility::getDefaultDBConnection();
     mysqli_autocommit($link, false);
     foreach ($regno as $value) {
         $query = "update users set is_suspended = 0, is_deleted = 0  where regno = '{$value}'";
         $ok = mysqli_query($link, $query);
         if (!$ok) {
             //Log error
             AdminUtility::logMySQLError($link);
             return FALSE;
         }
     }
     return mysqli_commit($link);
 }
Esempio n. 4
0
function getClassReps()
{
    $class_reps = array();
    $query = "select u.first_name, u.last_name, u.regno, u.level, m.user_id, m.units_used, m.units_assigned from admins a " . "join (users u, messenger_sms_biller m) on (u.regno = a.username and u.regno = m.user_id) " . "where a.type = '" . Admin::CLASS_REP . "' ";
    $link = AdminUtility::getDefaultDBConnection();
    $result = mysqli_query($link, $query);
    if ($result) {
        while ($row = mysqli_fetch_array($result)) {
            array_push($class_reps, $row);
        }
    }
    //Log error
    AdminUtility::logMySQLError($link);
    return $class_reps;
}
Esempio n. 5
0
 function removeExecutive($executiveID, $link = null)
 {
     $query = "delete from executives where id = '{$executiveID}'";
     if (empty($link)) {
         $link = AdminUtility::getDefaultDBConnection();
     }
     mysqli_query($link, $query);
     //Log error
     AdminUtility::logMySQLError($link);
 }
Esempio n. 6
0
function totalSmsSent($user_id)
{
    $query = "select sum(num_delivered) as num from messenger_log where user_id = '" . $user_id . "' and is_sent=1";
    $link = AdminUtility::getDefaultDBConnection();
    $result = mysqli_query($link, $query);
    if ($result) {
        $row = mysqli_fetch_array($result);
        return $row['num'];
    }
    //Log error
    AdminUtility::logMySQLError($link);
    return false;
}
Esempio n. 7
0
function getExecutivePosts()
{
    $posts = array();
    $query = "select * from posts";
    $link = AdminUtility::getDefaultDBConnection();
    $result = mysqli_query($link, $query);
    if ($result) {
        while ($row = mysqli_fetch_array($result)) {
            $posts[] = $row;
        }
    }
    //Log error
    AdminUtility::logMySQLError($link);
    return $posts;
}
         $num_of_recipients = count($required_contacts);
         $cost = $num_of_recipients * $num_of_sms_pages;
         if ($balance > $cost) {
             $settings = $admin->getSettings();
             $gateway = $settings['sms_api_gatewayURL']['value'];
             $username = $settings['sms_api_gatewayUsername']['value'];
             $password = $settings['sms_api_gatewayPassword']['value'];
             $sms = new SMS($gateway, $username, $password, $sender_id, $message_body, $recipients);
             if ($sms->send()) {
                 $units_used = $sms->get_unitsUsed();
                 $q2 = "update messenger_sms_biller set units_used=(units_used + " . $units_used . ") where user_id='" . $admin->getAdminID() . "'";
                 $q3 = "insert into messenger_log values(NULL,'" . $admin->getAdminID() . "','{$message_body}','{$recipients}'," . time() . ",1," . time() . "," . $units_used . ")";
                 $result2 = mysqli_query($link, $q2);
                 AdminUtility::logMySQLError($link);
                 $result3 = mysqli_query($link, $q3);
                 AdminUtility::logMySQLError($link);
             }
             $responce = $sms->get_responseText();
         } else {
             $responce = "You do not have enough balance at the moment.<br/>";
             $responce .= "You need additional " . ($cost - $balance) . " units to complete this action.";
         }
     } elseif ($type == 'email') {
         if (mail($recipients, 'Subject: ' . $subject, wordwrap($message, 70, '\\r\\n'), 'From: ' . $reply_to . '\\r\\n' . 'Reply-To: ' . $contact_email . '\\r\\n' . 'X-Mailer: PHP/' . phpversion())) {
             $responce = "You message has been delievered.";
         }
     } else {
     }
 }
 ?>
 <script>
Esempio n. 9
0
 public function updateSettingsTable(array $array)
 {
     if (count($array) > 0) {
         $link = AdminUtility::getDefaultDBConnection();
         mysqli_autocommit($link, false);
         $ok = true;
         foreach ($array as $key => $value) {
             /*            if (strcasecmp($key, "help_lines") === 0) {
                               validateNumbers($value);
                               }
             
                              */
             $query = "update settings set value = '{$value}' where name = '{$key}'";
             //$ok remains true if all statements was sucessfully executed
             $ok = $ok and mysqli_query($link, $query);
         }
         if ($ok) {
             mysqli_commit($link);
             //Log error
             AdminUtility::logMySQLError($link);
             return true;
         } else {
             throw new Exception("Error occured while updating settings table");
         }
     } else {
         throw new Exception("No parameter was set");
     }
 }
Esempio n. 10
0
function deleteLibraryItems(array $IDs)
{
    $link = AdminUtility::getDefaultDBConnection();
    mysqli_autocommit($link, false);
    foreach ($IDs as $value) {
        $query = "select * from library where id={$value}";
        $res = mysqli_query($link, $query);
        if ($res) {
            $row = mysqli_fetch_array($res);
            $query = "delete from library where id={$value}";
            $ok = mysqli_query($link, $query);
            if ($ok && $row['file_type'] !== "link") {
                //delete file from local server
                $ok = unlink(ROOT . $row['link']);
                if (!$ok) {
                    mysqli_rollback($link);
                    throw new Exception("File could not be deleted");
                }
            } elseif (!$ok) {
                //Log error
                AdminUtility::logMySQLError($link);
                throw new Exception("Oops! Something went wrong. Database didn't respond very well");
            }
        }
    }
    return mysqli_commit($link);
}
Esempio n. 11
0
 /**
  * 
  * @param type $search_query
  * @param type $sort_type
  * @param type $sort_order
  * @return array
  */
 public static function searchUsers($search_query, $is_deleted = false, $is_suspended = false, $sort_type = null, $sort_order = null)
 {
     $users = array();
     $link = AdminUtility::getDefaultDBConnection();
     //process query
     $fields = explode(" ", $search_query);
     $query = "select * from users where (is_deleted = " . ($is_deleted ? "1" : "0") . " and " . "is_suspended = " . ($is_suspended ? "1" : "0") . ") and " . "(";
     for ($count = 0; $count < count($fields); $count++) {
         $query .= "regno = '{$fields[$count]}' or " . "last_name like '%{$fields[$count]}%' or " . "level = '{$fields[$count]}' or " . "first_name like '%{$fields[$count]}%'";
         if ($count !== count($fields) - 1) {
             $query .= " or ";
         } else {
             $query .= ")";
         }
     }
     //Search
     $result = mysqli_query($link, $query);
     if ($result) {
         while ($row = mysqli_fetch_array($result)) {
             array_push($users, $row);
         }
     }
     AdminUtility::sortUser($users, $sort_type, $sort_order);
     //Log error
     AdminUtility::logMySQLError($link);
     return $users;
 }
Esempio n. 12
0
 public function saveItem()
 {
     $link = $this->DB_CON;
     $query = "update library set \n\t\t\ttitle = '" . $this->getTitle() . "',\n\t\t\tauthor = '" . $this->getAuthor() . "',\n\t\t\tpublisher = '" . $this->getPublisher() . "',\n\t\t\tdate_published = '" . $this->getDateOfPublication() . "',\n\t\t\tisbn = '" . $this->getISBN() . "',\n\t\t\tcategory = '" . $this->getCategory() . "',\n\t\t\tsub_category = '" . $this->getSubCategory() . "',\n\t\t\tkeywords = '" . $this->getKeywords() . "',\n\t\t\tcontributor = '" . $this->getContributor() . "',\n\t\t\tdate_added = '" . $this->getDateAdded() . "',\n\t\t\tfile_type = '" . $this->getFileType() . "',\n\t\t\tlink = '" . $this->getURL() . "',\n\t\t\ton_shelf = " . $this->is_onShelf() . "\n\t\t\twhere id = " . $this->getID();
     $result = mysqli_query($link, $query);
     if ($result) {
         return true;
     }
     //Log error
     AdminUtility::logMySQLError($link);
     exit;
 }
Esempio n. 13
0
 public function changeSenderID($new_id)
 {
     $link = AdminUtility::getDefaultDBConnection();
     $query = "update messenger_sms_biller set default_sender_id='" . $new_id . "' where user_id='" . $this->getAdminID() . "'";
     if (mysqli_query($link, $query)) {
         return true;
     }
     //Log error
     AdminUtility::logMySQLError($link);
     return false;
 }