/**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     if (Auth::check()) {
         $data["inside_url"] = Config::get('app.inside_url');
         $data["user"] = Session::get('user');
         $id_tipo = Input::get('id_tipo');
         // Verifico si el usuario es un Webmaster
         if ($data["user"]->idrol == 1 || $data["user"]->idrol == 2 || $data["user"]->idrol == 3 || $data["user"]->idrol == 4) {
             // Validate the info, create rules for the inputs
             $rules = array('actividad' => 'required', 'descripcion' => 'required', 'actividad_previa' => 'required', 'fecha_ini' => 'required', 'fecha_fin' => 'required', 'duracion' => 'required');
             $messages = array('fecha_ini.required' => 'El campo Fecha Inicio es requerido.', 'fecha_fin.required' => 'El campo Fecha Final es requerido.');
             // Run the validation rules on the inputs from the form
             $validator = Validator::make(Input::all(), $rules, $messages);
             // If the validator fails, redirect back to the form
             if ($validator->fails()) {
                 return Redirect::to('trabajo_cronograma/edit/' . $id)->withErrors($validator)->withInput(Input::all());
             } else {
                 $cronograma_actividad = new TrabajoCronogramaActividad();
                 $cronograma_actividad->nombre = Input::get('actividad');
                 $cronograma_actividad->descripcion = Input::get('descripcion');
                 $cronograma_actividad->id_actividad_previa = Input::get('actividad_previa');
                 $cronograma_actividad->fecha_ini = date("Y-m-d", strtotime(Input::get('fecha_ini')));
                 $cronograma_actividad->fecha_fin = date("Y-m-d", strtotime(Input::get('fecha_fin')));
                 $cronograma_actividad->duracion = Input::get('duracion');
                 $cronograma_actividad->id_cronograma = $id;
                 $cronograma_actividad->save();
                 $cronograma = Cronograma::find($id);
                 Session::flash('message', 'Se editó correctamente el cronograma.');
                 return Redirect::to('trabajo_cronograma/show/' . $id);
             }
         } else {
             return View::make('error/error', $data);
         }
     } else {
         return View::make('error/error', $data);
     }
 }
 /**
  * Obtiene un cronograma por su id
  *
  * @param $id
  * @return Cronograma
  */
 public function getCronogramaById($id)
 {
     return Cronograma::where('id_cronograma', $id)->first();
 }
 public function getActividadesAjax()
 {
     if (!Request::ajax() || !Auth::check()) {
         return Response::json(array('success' => false), 200);
     }
     $id = Auth::id();
     $data["inside_url"] = Config::get('app.inside_url');
     $data["user"] = Session::get('user');
     if ($data["user"]->idrol == 1 || $data["user"]->idrol == 2 || $data["user"]->idrol == 3 || $data["user"]->idrol == 4 || $data["user"]->idrol == 5 || $data["user"]->idrol == 6 || $data["user"]->idrol == 7 || $data["user"]->idrol == 8 || $data["user"]->idrol == 9 || $data["user"]->idrol == 10 || $data["user"]->idrol == 11 || $data["user"]->idrol == 12) {
         // Check if the current user is the "System Admin"
         $id_cronograma = Input::get('id_cronograma');
         $id_tipo = Input::get('id_tipo');
         if ($id_cronograma != "" && $id_tipo != "") {
             $cronograma = Cronograma::find($id_cronograma);
             if ($id_tipo == 0) {
                 $actividades = [0 => 'No posee actividad previa'] + $cronograma->actividades->lists('nombre', 'id');
             } else {
                 $actividades = [0 => 'No posee actividad previa'] + $cronograma->actividadespost->lists('nombre', 'id');
             }
         } else {
             $actividades = [0 => 'No posee actividad previa'];
         }
         return Response::json(array('success' => true, 'actividades' => $actividades), 200);
     } else {
         return Response::json(array('success' => false), 200);
     }
 }