/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $group = $this->groups->find($id); Javascript::put('groups', MemberGroup::all()); Javascript::put('form', $group); return view('backend.forums.membergroups.edit'); }
/** * @return $this */ public function index() { // SEO Meta settings $this->seo_meta['page_title'] = trans('seo.back.dashboard.index'); $now = Carbon::now(); $pre_formatted_periods = []; // 7 last days $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_7_days'] = ['start_date' => $referrer_start->subDays(7)->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subDays(1)->endOfDay()->format('d/m/Y H:i')]; // last week $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_complete_week'] = ['start_date' => $referrer_start->subWeek()->startOfWeek()->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subWeek()->endOfWeek()->endOfDay()->format('d/m/Y H:i')]; // 30 last days $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_30_days'] = ['start_date' => $referrer_start->subDays(30)->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subDays(1)->endOfDay()->format('d/m/Y H:i')]; // last month $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_complete_month'] = ['start_date' => $referrer_start->subMonth()->startOfMonth()->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subMonth()->endOfMonth()->endOfDay()->format('d/m/Y H:i')]; // 90 last days $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_90_days'] = ['start_date' => $referrer_start->subDays(90)->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subDays(1)->endOfDay()->format('d/m/Y H:i')]; // 3 last months $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_3_complete_months'] = ['start_date' => $referrer_start->subMonths(3)->startOfMonth()->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subMonth()->endOfMonth()->endOfDay()->format('d/m/Y H:i')]; // 180 last days $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_180_days'] = ['start_date' => $referrer_start->subDays(180)->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subDays(1)->endOfDay()->format('d/m/Y H:i')]; // 6 last months $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_6_complete_months'] = ['start_date' => $referrer_start->subMonths(6)->startOfMonth()->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subMonth()->endOfMonth()->endOfDay()->format('d/m/Y H:i')]; // this year $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['this_year'] = ['start_date' => $referrer_start->startOfYear()->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->endOfDay()->format('d/m/Y H:i')]; // last year $referrer_start = clone $now; $referrer_end = clone $now; $pre_formatted_periods['last_year'] = ['start_date' => $referrer_start->subYear()->startOfYear()->startOfDay()->format('d/m/Y H:i'), 'end_date' => $referrer_end->subYear()->endOfYear()->endOfDay()->format('d/m/Y H:i')]; Javascript::put(['pre_formatted_periods' => $pre_formatted_periods, 'trans' => ['visitors' => trans('dashboard.statistics.label.visitors'), 'page_views' => trans('dashboard.statistics.label.page_views'), 'pages' => trans('dashboard.statistics.label.pages'), 'url' => trans('dashboard.statistics.label.url'), 'views' => trans('dashboard.statistics.label.views'), 'form_downloads' => trans('dashboard.statistics.label.form_downloads'), 'qr_code_scans' => trans('dashboard.statistics.label.qr_code_scans')]]); // prepare data for the view $data = ['seo_meta' => $this->seo_meta, 'pre_formatted_periods' => $pre_formatted_periods]; // return the view with data return view('pages.back.dashboard')->with($data); }
/** * View the permissions page for the given board ID * * @param $id * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function viewPermissions($id) { $board = $this->boards->find($id); $defaultPermissions = $board->getDefaultPermissions()->toArray(); $groups = MemberGroup::all(); $groupsArray = array(); foreach ($groups as $group) { //dd($group->permissions()->Board($id)->first()); if ($groupPermission = $group->permissions()->Board($id)->first()) { $groupsArray[$group->name] = $groupPermission->toArray(); } else { $groupsArray[$group->name] = $group->permissions()->Board($id)->create(array_add($defaultPermissions, 'board_id', $id)); } } Javascript::put("board", $board); Javascript::put("permissions", $groupsArray); return view('backend.forums.boards.permissions'); }
public function mostrarDetalle($cuadrante_id) { function getClient() { $client = new Google_Client(); $client->setApplicationName(APPLICATION_NAME); $client->setScopes(SCOPES); $client->setAuthConfigFile(CLIENT_SECRET_PATH); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); //esta linea la he añadido yo // Load previously authorized credentials from a file. $credentialsPath = CREDENTIALS_PATH; // dd($credentialsPath); if (file_exists($credentialsPath)) { $accessToken = file_get_contents($credentialsPath); } else { // Request authorization from the user. dd('no hay autorización, habrá que modificar el código'); $authUrl = $client->createAuthUrl(); printf("Open the following link in your browser:\n%s\n", $authUrl); print 'Enter verification code: '; $authCode = trim(fgets(STDIN)); // Exchange authorization code for an access token. $accessToken = $client->authenticate($authCode); // Store the credentials to disk. if (!file_exists(dirname($credentialsPath))) { mkdir(dirname($credentialsPath), 0700, true); } file_put_contents($credentialsPath, $accessToken); // printf("Credentials saved to %s\n", $credentialsPath); } $client->setAccessToken($accessToken); // Refresh the token if it's expired. if ($client->isAccessTokenExpired()) { $client->refreshToken($client->getRefreshToken()); file_put_contents($credentialsPath, $client->getAccessToken()); } return $client; } function listMessages($service, $userId, $fecha, $email) { $pageToken = NULL; $messages = array(); $opt_param = array(); //mensaje de ese empleado para ese día $opt_param['q'] = 'subject:' . $fecha . ' from:' . $email . ' label:Inbox'; do { try { if ($pageToken) { $opt_param['pageToken'] = $pageToken; } $messagesResponse = $service->users_messages->listUsersMessages($userId, $opt_param); if ($messagesResponse->getMessages()) { $messages = array_merge($messages, $messagesResponse->getMessages()); $pageToken = $messagesResponse->getNextPageToken(); } } catch (Exception $e) { print 'An error occurred: ' . $e->getMessage(); } } while ($pageToken); return $messages; } function modifyMessage($service, $userId, $messageId, $labelsToAdd, $labelsToRemove) { $mods = new Google_Service_Gmail_ModifyMessageRequest(); $mods->setAddLabelIds($labelsToAdd); $mods->setRemoveLabelIds($labelsToRemove); try { $message = $service->users_messages->modify($userId, $messageId, $mods); // print 'Message with ID: ' . $messageId . ' successfully modified.'; return $message; } catch (Exception $e) { print 'An error occurred: ' . $e->getMessage(); } } function getHeader($headers, $name) { foreach ($headers as $header) { if ($header['name'] == $name) { return $header['value']; } } } function getHeaders($headers, $campos) { foreach ($headers as $header) { for ($i = 0; $i < count($campos); $i++) { if ($header['name'] == $campos[$i]) { $results[$campos[$i]] = $header['value']; } } } return $results; } // function getBody($partes){ // foreach($partes as $parte){ // if($parte['name'] == 'body') // } // } /* * Decode the body. * @param : encoded body - or null * @return : the body if found, else FALSE; */ function decodeBody($body) { $rawData = $body; $sanitizedData = strtr($rawData, '-_', '+/'); $decodedMessage = base64_decode($sanitizedData); if (!$decodedMessage) { $decodedMessage = FALSE; } return $decodedMessage; } $cuadrante = Cuadrante::where('id', $cuadrante_id)->first(); $lineas = LineaCuadrante::where('cuadrante_id', $cuadrante_id)->orderBy('tipo', 'asc')->orderBy('salida', 'asc')->get(); $fecha = $cuadrante->fecha; $fecha = date_format($fecha, 'd-m-Y'); $valores = $this->empleadosTrabajando($cuadrante_id); Javascript::put(['valores' => $valores]); if ($cuadrante->estado == 'Validado') { define('APPLICATION_NAME', 'Gmail API PHP Quickstart'); define('CREDENTIALS_PATH', base_path() . '/storage/app/.credentials/gmail-php-quickstart.json'); define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json'); // If modifying these scopes, delete your previously saved credentials define('SCOPES', implode(' ', array(Google_Service_Gmail::GMAIL_MODIFY))); /** * Returns an authorized API client. * @return Google_Client the authorized client object */ // Get the API client and construct the service object. $client = getClient(); $service = new Google_Service_Gmail($client); $userId = 'me'; // lista de labels con ids // $results = $service->users_labels->listUsersLabels($userId); // dd($results); $messages = listMessages($service, $userId, $fecha, null); if ($messages) { foreach ($lineas as $linea) { $email = $linea->empleado->email; $mensaje = listMessages($service, $userId, $fecha, $email); // $labelsToAdd = ['Label_1']; $labelsToRemove = ['INBOX']; if (count($mensaje) == 1) { // dd('hay uno'); $linea->mensaje_id = $mensaje[0]->id; $detalle_mensaje = $service->users_messages->get($userId, $mensaje[0]->id); $headers = $detalle_mensaje->getPayload()->getHeaders(); $partsBody = $detalle_mensaje->getPayload()->getParts(); $body = decodeBody($partsBody[0]['body']['data']); $campos = array('Subject', 'Date'); $results = getHeaders($headers, $campos); $linea->asunto = $results['Subject']; $fechaLocal = date("Y-m-d H:i:s", strtotime($results['Date'])); $linea->fechaMensaje = $fechaLocal; $linea->body = $body; // $subject = getHeader($headers, 'Subject'); // $linea->asunto = $subject; $linea->estado = 'Firmado'; $linea->save(); // modifyMessage($service,$userId,$linea->mensaje_id,$labelsToAdd,$labelsToRemove); modifyMessage($service, $userId, $linea->mensaje_id, ['Label_1'], $labelsToRemove); } else { if (count($mensaje) > 1) { //archivo en duplicados(Label_2) los antiguos // dd(count($mensaje)); for ($i = 1; $i < count($mensaje); $i++) { $detalle_mensaje = $service->users_messages->get($userId, $mensaje[$i]->id); $headers = $detalle_mensaje->getPayload()->getHeaders(); $subject = getHeader($headers, 'Subject'); modifyMessage($service, $userId, $mensaje[$i]->id, ['Label_2'], $labelsToRemove); } } else { if (!count($mensaje)) { // no hay ninguno y continua el foreach } } } } } } return view('controlHorario.detalleCuadrante', compact('cuadrante', 'lineas')); }
/** * Show the application dashboard. * * @return Response */ public function index() { Javascript::put(['portfolio' => Portfolio::all()]); return view('dashboard.index'); }