Beispiel #1
0
    $fileErrorMsg = $_FILES["myfile"]["error"];
    //0 for false and 1 for true
    if (!$fileTmpLoc) {
        die(new ModelResponse(false, 'Please browse for a valid file'));
    }
    $destPath = "{$uploadPath}/{$fileName}";
    if (move_uploaded_file($fileTmpLoc, $destPath)) {
        $raw_data = CSV::Parse($destPath);
        // Get initial user list
        $currentUserList = new Models\UserList();
        // Initialize container
        $userList = new Models\UserList(false);
        // proceed with creation
        foreach ($raw_data as $row) {
            $user = new Models\User();
            if ($currentUserList->ContainsUsername($row['username'])) {
                $user = \Models\User::FindUsername(strtolower(trim($row['username'])));
            } else {
                $user->Absorb($row);
            }
            $userList->add($user);
        }
        if (!$userList->Create()) {
            die(ModelResponse::DataSaveFailed());
        }
        $response = new ModelResponse(true, 'Data import success!', $userList);
        die($response);
    } else {
        die(ModelResponse::Busy());
    }
}
Beispiel #2
0
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * [REST_META]
 *
 * username (string)
 *
 */
header('Content-type: application/json');
require_once ROOT_PATH . 'includes/load_admin_usernames.php';
$expectations = ['username'];
if (!\Utilities\Requests::HasRequest($expectations)) {
    die(ModelResponse::InvalidRequest());
}
$is_admin = is_admin($_REQUEST['username']);
$user = null;
if ($is_admin) {
    $user = \Models\User::FindUsername($_REQUEST['username']);
    die(new ModelResponse(true, 'Yes, an admin', $user));
} else {
    die(new ModelResponse(false, sprintf('User \\"%s\\" is not an admin', $_REQUEST['username'])));
}
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * id (int) -- ID of sickleave to be marked as read
 *
 */
header('Content-type: application/json');
// Check request
if (!\Utilities\Requests::HasRequest(['id'])) {
    die(ModelResponse::InvalidRequest());
}
// Check session
if (!\Utilities\Session::IsLoggedIn()) {
    die(ModelResponse::NoSession());
}
// Check if admin
$sessData = \Utilities\Session::Initialize();
if ($sessData instanceof Models\SessionData) {
    if (!$sessData->getUser()->isAdmin()) {
        die(new ModelResponse(false, 'Sorry, but you are not authorized to do so'));
    }
}
// Otherwise proceed
$sickLeave = Models\Sickleave::Find($_REQUEST['id'], 'sickleave');
if ($sickLeave instanceof Models\Sickleave) {
}
// intellisense only
if ($sickLeave->notifstatus == 'UNREAD' || is_string($sickLeave->read_on) && strlen($sickLeave->read_on) == 0) {
    // This is not yet read
Beispiel #4
0
 /**
  * Create an instance of this Model from an ID (optionally, also table name). Returns NULL if none found
  *
  * @param int $id
  * @param string $tableName The name of table to derive from
  *
  * @return mixed
  */
 public static function Find($id, $tableName)
 {
     $db = \DB::Instance();
     $rows = $db->select($tableName, '*', ['id' => $id]);
     $modelClass = sprintf('\\Models\\%s', ltrim(ucfirst(strtolower($tableName)), '\\Models\\'));
     $model = new $modelClass();
     if ($rows === false) {
         $model->SetState(ModelResponse::NoData());
     } else {
         if (sizeof($rows) == 0) {
             $model->SetState(ModelResponse::NoData());
             return $model;
         } else {
             $rows = $rows[0];
         }
         $keys = array_keys($rows);
         foreach ($keys as $key) {
             $model->{strtolower($key)} = $rows[strtolower($key)];
         }
     }
     return $model;
 }
 * span (decimal)
 * reason (string)
 *
 */
header('Content-type: application/json');
$expectations = ['author_id', 'for_id', 'date', 'span', 'reason'];
if (!\Utilities\Requests::HasRequest($expectations)) {
    die(ModelResponse::InvalidRequest());
}
$raw_data = [];
foreach ($_REQUEST as $key => $value) {
    if (in_array($key, $expectations)) {
        $raw_data[$key] = $value;
    }
}
$newSickleave = new \Models\Sickleave();
$newSickleave->Absorb($raw_data);
if (!$newSickleave->SaveAll()) {
    die(ModelResponse::DataSaveFailed());
}
// Otherwise, success
// Notify via email
$isNotificationEnabled = Utilities\Config::get('email_notification', CONFIG_PATH . 'application.ini');
if ($isNotificationEnabled == 1) {
    try {
        Utilities\Email::NotifyAdmins($newSickleave);
    } catch (phpmailerException $ex) {
        $newSickleave->SetState(new ModelResponse(false, 'Failure on notifying admins: ' . $ex->getMessage()));
    }
}
die(new ModelResponse(true, "Sick leave entry has been successfully added!", $newSickleave));