Beispiel #1
0
 /**
  * Fetch an item from the POST array and trim spaces at the beginning an end
  *
  * @param   string  The index key
  * @param   mixed   The default value
  * @return  string|array
  *
  * @access public
  *
  * @author Dao Anh Minh
  * @version 1.0
  * @since 1.0
  */
 public static function post($index = null, $default = null)
 {
     //get POST value
     $post = parent::post($index, $default);
     //return POST value with trim all spaces at the beginning and end
     return trim_post($post);
 }
Beispiel #2
0
 public function action_create($id = null)
 {
     if (Fuel\Core\Input::post()) {
         $comment = Model_Comment::forge(array('name' => Fuel\Core\Input::post('comment'), 'comment' => Fuel\Core\Input::post('comment'), 'message_id' => Fuel\Core\Input::post('message_id')));
         if ($comment and $comment->save()) {
             Fuel\Core\Session::set_flash('success', 'Added comment #' . $comment->id . '.');
             Fuel\Core\Response::redirect('messages/view/' . $comment->message_id);
         } else {
             Fuel\Core\Session::set_flash('error', 'Could not save comment');
         }
     } else {
         $this->template->set_global('message', $id, false);
     }
     $data["subnav"] = array('create' => 'active');
     $this->template->title = 'Comments » Create';
     $data['form'] = View::forge('comments/_form');
     $this->template->content = View::forge('comments/create', $data);
 }
 public function action_logtimes($timestamp = null)
 {
     if (!Auth\Auth::has_access('timesheets.read')) {
         Fuel\Core\Session::set_flash('error', 'You do not have access to view timesheets');
         Fuel\Core\Response::redirect('user');
     }
     if (!$timestamp) {
         $timestamp = \Fuel\Core\Date::forge()->get_timestamp();
         // today
     }
     if (Fuel\Core\Input::method() == 'POST') {
         try {
             // start a db transaction
             \Fuel\Core\DB::start_transaction();
             // find all logs for this task for this day
             $date = date('Y-m-d', $timestamp);
             $starts = date('Y-m-d 00:00:00', $timestamp);
             $ends = date('Y-m-d 23:59:59', $timestamp);
             $project_task_logs = Model_Projecttasklog::find('all', array('related' => array('project_task'), 'where' => array(array('project_task.user_id', $this->current_user->id), array('task_started', 'BETWEEN', array($starts, $ends)))));
             foreach ($project_task_logs as $log) {
                 $date_starts = date('Y-m-d', $timestamp);
                 $date_ends = date('Y-m-d 23:59:59', $timestamp);
                 if ($log->get_project_task()->user_id == $this->current_user->id) {
                     if (in_array(strtotime($log->task_started), range(strtotime($date_starts), strtotime($date_ends)))) {
                         // delete the logs
                         $log->delete();
                     }
                 }
             }
             // insert new logs
             if (Fuel\Core\Input::post('timeslots')) {
                 $date = date('Y-m-d', $timestamp);
                 $last_comment = '';
                 $last_task_id = '';
                 foreach (Fuel\Core\Input::post('timeslots') as $str) {
                     $times = explode('_', $str);
                     $is_billable = 0;
                     $task_started = $date . ' ' . $times[0] . ':00';
                     $task_completed = $date . ' ' . $times[1] . ':00';
                     $project_task_id_array = Fuel\Core\Input::post('project_task_id');
                     $task_id = $project_task_id_array["'{$str}'"];
                     if (Fuel\Core\Input::post('comment_' . $str) != '') {
                         $last_comment = Fuel\Core\Input::post('comment_' . $str);
                     }
                     if (intval(Fuel\Core\Input::post('is_billable_' . $str, '0')) == 1) {
                         $is_billable = 1;
                     }
                     if (empty($task_id)) {
                         $task_id = $last_task_id;
                     } else {
                         $last_task_id = $task_id;
                     }
                     if (empty($task_id)) {
                         continue;
                         // todo - display error
                     }
                     $task_log = Model_Projecttasklog::forge(array('project_task_id' => $task_id, 'comment' => $last_comment, 'task_started' => $task_started, 'task_completed' => $task_completed, 'is_billable' => $is_billable));
                     $task_log->save();
                 }
             }
             // commit to database
             \Fuel\Core\DB::commit_transaction();
             \Fuel\Core\Session::set_flash('success', 'Time logs saved successfully.');
             Fuel\Core\Response::redirect('user/timesheets/index/' . $timestamp);
         } catch (Exception $ex) {
             // rollback on error
             \Fuel\Core\DB::rollback_transaction();
             \Fuel\Core\Session::set_flash('error', $ex->getMessage());
             Fuel\Core\Response::redirect('user/timesheets/advanced/logtimes/' . $timestamp);
         }
     }
     $now = \Fuel\Core\Date::forge($timestamp)->format('mysql');
     $day_starts = date('Y-m-d 00:00:00', strtotime($now));
     $day_ends = date('Y-m-d 23:59:59', strtotime($now));
     $today_logs = Model_Projecttasklog::find('all', array('related' => array('project_task', 'project_task.project', 'project_task.project_task_name', 'project_task.user'), 'where' => array(array('task_started', 'BETWEEN', array($day_starts, $day_ends)), array('project_task.user_id', $this->current_user->id)), 'order_by' => array(array('task_started', 'asc'))));
     // todo: use DB::query() instead
     $this->template->set_global('today_logs', $today_logs);
     $this->template->set_global('projects', Model_Project::find('all', array('order_by' => array(array('name', 'asc')))));
     $this->template->set_global('timezones', Model_Timezone::find('all', array('order_by' => array(array('starts', 'asc')))));
     $this->template->set_global('my_tasks', Model_Projecttask::find('all', array('where' => array(array('user_id', $this->current_user->id)), 'related' => array('project_task_name'), 'order_by' => array(array('project_task_description', 'asc')))));
     $this->template->set_global('timestamp', $timestamp);
     $this->template->set_global('date', \Fuel\Core\Date::forge($timestamp)->format('mysql_date'));
     $this->template->title = 'Timesheets';
     $this->template->content = View::forge('user/timesheets/advanced/_advanced_form');
 }
Beispiel #4
0
<fieldset>
    <div class="form-group">
        <?php 
echo \Fuel\Core\Form::label('Name', 'name', array('class' => 'control-label'));
?>
        <?php 
echo \Fuel\Core\Form::input('name', isset($comment->name) ? $comment->name : '', array('class' => 'form-control'));
?>
    </div>
    
    <div class="form-group">
        <?php 
echo \Fuel\Core\Form::label('Comment', 'comment', array('class' => 'control-label'));
?>
        <?php 
echo \Fuel\Core\Form::textarea('comment', Fuel\Core\Input::post('comment', isset($comment) ? $comment->comment : ''), array('class' => 'form-control'));
?>
        
    </div>
</fieldset>

<div class="actions">
    <?php 
echo \Fuel\Core\Form::hidden('message_id', isset($message) ? $message : '');
?>
    <?php 
echo \Fuel\Core\Form::submit('submit', 'Submit', array('class' => 'btn btn-primary'));
?>
</div>

<?php 
 /**
  * 
  * @param type $task_log_id
  */
 public function action_edittimes($task_log_id = null)
 {
     if (Fuel\Core\Input::method() == 'POST') {
         $task_log_id = Fuel\Core\Input::post('id');
     }
     if (!($task_log = Model_Projecttasklog::find($task_log_id))) {
         \Fuel\Core\Session::set_flash('error', 'Cannot find task log # ' . $task_log_id);
         \Fuel\Core\Response::redirect_back('user/timesheets');
     }
     if (Fuel\Core\Input::method() == 'POST') {
         $val = Model_Projecttasklog::validate('edit');
         if ($val->run()) {
             $task_log->comment = Fuel\Core\Input::post('comment');
             $task_log->task_started = Fuel\Core\Input::post('task_started') . ' ' . Fuel\Core\Input::post('task_started_hr') . ':' . Fuel\Core\Input::post('task_started_min') . ':00';
             $task_log->task_completed = Fuel\Core\Input::post('task_completed') . ' ' . Fuel\Core\Input::post('task_completed_hr') . ':' . Fuel\Core\Input::post('task_completed_min') . ':00';
             if ($task_log->save()) {
                 \Fuel\Core\Session::set_flash('success', 'Saved time log for task # ' . $task_log_id);
                 \Fuel\Core\Response::redirect('user/timesheets/view/' . $task_log->project_task_id);
             } else {
                 \Fuel\Core\Session::set_flash('error', 'Cannot save task log # ' . $task_log_id);
             }
         } else {
             \Fuel\Core\Session::set_flash('error', $val->error());
         }
     }
     $view = \Fuel\Core\View::forge('user/timesheets/edittimes');
     $view->set_global('task_log', $task_log);
     $view->set_global('task', $task_log->project_task);
     $this->template->user_is_admin = $this->check_user_is_admin();
     $this->template->title = 'Timesheets';
     $this->template->content = $view;
 }