· 6 years ago · Jul 03, 2019, 03:36 PM
1<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2
3define('PASS', 'abracadabra12345');
4
5class scheduledJob extends CI_Controller
6{
7 function getEmailAddress($id)
8 {
9 $this->load->model('main_model');
10 $this->main_model->db_test_gamification();
11 $query = $this->db->query("select user_email from user where user_id = $id;");
12 return "'" . $query->row()->user_email . "'";
13
14 }
15
16 function mail_notifica($id, $ultima, $cardinalita)
17 {
18
19 $this->load->model('main_model');
20 $this->load->helper("url");
21 $this->main_model->db_test_gamification();
22
23 echo $_SERVER['REMOTE_ADDR'];
24
25
26 $config = Array(
27 'protocol' => 'smtp',
28 'smtp_host' => 'ssl://smtp.gmail.com',
29 'smtp_port' => 465,
30 'smtp_user' => 'pepegatest@gmail.com',
31 'smtp_pass' => PASS,
32 'mailtype' => 'html',
33 'charset' => 'utf-8',
34 'wordwrap' => TRUE
35
36 );
37
38 $this->load->library('email', $config);
39
40 $this->email->set_mailtype("html");
41 $this->email->set_newline("\r\n");
42// $addres = $this->getEmailAddress($id);
43// $this->email->to($addres);
44 $this->email->to('rick.espa@gmail.com');
45 $this->email->from('pepegatest@gmail.com', 'u4fit');
46
47 $this->email->subject("Medaglia raggiunta");
48
49 $medals_url = base_url() . "index.php/medals";
50
51 $mail_content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
52<html xmlns=3D\"http://www.w3.org/1999/xhtml\">
53 <head>
54 <meta http-equiv=3D\"content-type\" content=3D\"text/html; charset=3Dutf-8\"/>
55 <title>Notifica</title>
56</head>
57<body>
58 <div style=\"text-align: center\">
59 <h1>COMPLIMENTI!!</h1>
60 <h2>Hai raggiunto la medaglia " . $ultima . " per la " . $cardinalita . "^ volta.</h2>
61
62 <div>
63 <img src='http://research.u4fit.com/tmp/" . $ultima . ".png'
64 style='width: 500px; height: 500px'>
65 </div>
66 <div>
67 <h3>Per contorllare i tuoi progressi con le medaglie</h3>
68
69 <a href=" . $medals_url . " target=\"_blank\"><h4> Clicca qui </h4></a>
70 </div>
71 </div>
72</body>
73</html>
74 ";
75
76 $this->email->message($mail_content);
77
78 echo $this->email->send();
79 echo $this->email->print_debugger();
80
81 }
82
83 function medals_notification($id)
84 { //da iterare su tutti gli utenti
85 $this->load->model('main_model');
86 $this->main_model->db_test_gamification_local();
87 $this->load->helper("url");
88
89 $old_values = $this->main_model->get_last_notified($id);
90
91 $totKm = $this->main_model->getKm($id);
92 if ($totKm == null)
93 return;
94
95 $check_value = $this->main_model->check_for_medals_noitification($id, $totKm, $old_values);
96
97 if ($check_value == null)
98 return;
99 else {
100// echo $check_value['ultima'];
101// echo $check_value['cardinalita'];
102 $this->mail_notifica($id, $check_value['ultima'], $check_value['cardinalita']);
103 }
104
105
106 }
107
108 public function challenges()
109 {
110 $this->load->model('main_model');
111 $this->main_model->db_test_gamification_local();
112 $this->load->helper("url");
113
114 echo $_SERVER['REMOTE_ADDR'];
115
116 if ($_SERVER['SERVER_ADDR'] != $_SERVER['REMOTE_ADDR']) {
117 $this->output->set_status_header(400, 'No Remote Access Allowed');
118 exit;
119 } else {
120 //Disattivo le vecchie sfide
121
122 $this->db->query("UPDATE challenge SET active = 0 WHERE active = 1;");
123
124 //creo tre nuove sfide
125 $this->db->query("INSERT INTO challenge values( DEFAULT, CURRENT_TIMESTAMP, TIMESTAMPADD(DAY, +7, CURRENT_TIMESTAMP), 1, NULL, 0, true);");
126 $this->db->query("INSERT INTO challenge values( DEFAULT, CURRENT_TIMESTAMP, TIMESTAMPADD(DAY, +7, CURRENT_TIMESTAMP), 2, NULL, 0, true);");
127 $this->db->query("INSERT INTO challenge values( DEFAULT, CURRENT_TIMESTAMP, TIMESTAMPADD(DAY, +7, CURRENT_TIMESTAMP), 3, NULL, 0, true);");
128 echo "completed";
129 }
130 }
131
132 public function points()
133 {
134 $this->load->model('main_model');
135 $this->main_model->db_test_gamification();
136 $this->load->helper("url");
137
138 echo $_SERVER['REMOTE_ADDR'];
139
140 if ($_SERVER['SERVER_ADDR'] != $_SERVER['REMOTE_ADDR']) {
141
142 $this->db->query("SET @row_number = 0;");
143 $aux = DEV;
144 $query = $this->db->query("select distinct user_id, ROUND(sum(distance)/1000) as km, (@row_number:=@row_number + 1) as rank from user join workoutItem on user_id=item_user_id
145 where month(creationdate) = month(timestampadd(year, $aux, timestampadd(month, -1,current_timestamp()))) and year(creationdate) = year(timestampadd(year, $aux, timestampadd(month, -1,current_timestamp())))
146 group by user_id order by sum(distance) desc ;");
147 $punti_primo = 1000;
148 $pos = 0;
149 $punti = 0;
150
151 $premiati = intval(($query->num_rows()) / 2);
152 $this->main_model->db_test_gamification_local();
153
154 foreach ($query->result() as $raw) {
155 $pos = $raw->rank;
156 $punti = intval($punti_primo * ((1 + $premiati - $pos) / $premiati));
157 if ($punti <= 0) ;
158 else {
159 $this->db->query("INSERT into test_gamification_local.points VALUES($raw->user_id, $punti, current_timestamp(), 'Per aver raggiunto la posizione $pos in classifica il mese scorso');");
160 }
161 }
162 echo " completed";
163 }
164 }
165
166 public function mailsenderMonthly()
167 {
168
169 $this->load->model('main_model');
170 $this->main_model->db_test_gamification();
171 $this->load->helper("url");
172 $setup_link = base_url() . "index.php/nickname_setup";
173
174 $utenti = $this->main_model->getAllUsersAndNicknames()->result();
175
176
177 $config = Array(
178 'protocol' => 'smtp',
179 'smtp_host' => 'ssl://smtp.gmail.com',
180 'smtp_port' => 465,
181 'smtp_user' => 'pepegatest@gmail.com',
182 'smtp_pass' => PASS,
183 'mailtype' => 'html',
184 'charset' => 'utf-8',
185 'wordwrap' => TRUE
186
187 );
188
189 $this->load->library('email', $config);
190
191 $this->email->set_mailtype("html");
192 $this->email->set_newline("\r\n");
193
194 $newdate = date("M Y", strtotime("-1 months"));
195 foreach ($utenti as $row) {
196 $this->email->to('rick.espa@gmail.com');
197 $this->email->from('pepegatest@gmail.com', 'Classifica Mensile');
198 $this->email->subject("Classifica Mensile");
199
200 $mail_content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
201<html xmlns=3D\"http://www.w3.org/1999/xhtml\">
202 <head>
203 <meta http-equiv=3D\"content-type\" content=3D\"text/html; charset=3Dutf-8\"/>
204 <title>email</title>
205 <style>
206 .margin-5 {
207 margin: 5px;
208 }
209
210 .margin-top-10 {
211 margin-top: 10px;
212 }
213
214 .standings_points {
215 background-color: #ff3300 !important;
216 color: white !important;
217 display: inline-block;
218 width: 350px;
219 padding: 20px !important;
220 }
221 .standings_distance {
222 background-color: #7d8700 !important;
223 color: white !important;
224 display: inline-block;
225 width: 350px;
226 padding: 20px !important;
227 }
228
229 .standings_time {
230 background-color: #ff9600 !important;
231 color: white !important;
232 display: inline-block;
233 width: 350px;
234 padding: 20px !important;
235 }
236
237 .prog{
238 height:auto;
239 text-align:center;
240 }
241 .standings{
242 text-align:center !important;
243 }
244 </style>
245
246
247
248 </head>
249 <body>
250 <div dir=\"ltr\">
251 <div class='container' style=\" height:auto; text-align:center !important; \">
252 <h3 style=\"font-size: 28px !important;\">Riepilogo mensile" . "</h3>
253 <h4 style=\"font-size: 21px !important;\">" . $newdate . "</h4>
254 <table style=\"text-align:center; margin-left:auto; margin-right:auto\">
255 <tr>
256 <th class='jumbotron standings_distance margin-5 margin-top-10'
257 style=' padding:10px; width:110px; background-color: #7d8700 !important; color: white !important; padding: 20px !important; border-radius: 6px;'>
258 <h6 style='text-align:right;'> km </h6>
259 <h4 style=\"font-size: 21px !important;\">";
260
261 $mail_content = $mail_content . $this->main_model->getMyKmById_m(-1, $row->user_id);
262 $mail_content = $mail_content . "</h4><h5>";
263
264 if ($this->main_model->getMyKmById_m(-2, $row->user_id) != 0) {
265 $mail_content = $mail_content . ceil((($this->main_model->getMyKmById_m(-1, $row->user_id) - $this->main_model->getMyKmById_m(-2, $row->user_id)) / ($this->main_model->getMyKmById_m(-2, $row->user_id))) * 100) . "%";
266 } else {
267 $mail_content = $mail_content . "0%";
268 }
269
270
271 $mail_content = $mail_content . "</h5>
272 </th>
273
274 <th class='jumbotron standings_time margin-5 margin-top-10'
275 style=' padding:10px; width:110px; background-color: #ff9600 !important; color: white !important; padding: 20px !important; border-radius: 6px;'>
276 <h6 style='text-align:right;'> hh:mm </h6>
277 <h4 style=\"font-size: 21px !important;\">";
278 $mail_content = $mail_content . $this->main_model->seconds($this->main_model->getMyTimeById_m(-1, $row->user_id));
279 $mail_content = $mail_content . "</h4><h5>";
280
281 if ($this->main_model->getMyTimeById_m(-2, $row->user_id) != 0) {
282 $mail_content = $mail_content . ceil((($this->main_model->getMyTimeById_m(-1, $row->user_id) - $this->main_model->getMyTimeById_m(-2, $row->user_id)) / ($this->main_model->getMyTimeById_m(-2, $row->user_id))) * 100) . "%";
283
284 } else {
285 $mail_content = $mail_content . "0%";
286 }
287
288 $mail_content = $mail_content . "</h5>
289 </th>
290
291 <th class='jumbotron standings_points margin-5 margin-top-10'
292 style=' padding:10px; width:110px; background-color: #ff3300 !important; color: white !important; padding: 20px !important; border-radius: 6px;'>
293 <h6 style='text-align:right;'> punti </h6>
294 <h4 style=\"font-size: 21px !important;\">";
295 $mail_content = $mail_content . $this->main_model->getMyPById_m(-1, $row->user_id);
296 $mail_content = $mail_content . "</h4><h5>";
297
298 if ($this->main_model->getMyPById_m(-2, $row->user_id) != 0) {
299 $mail_content = $mail_content . ceil((($this->main_model->getMyPById_m(-1, $row->user_id) - $this->main_model->getMyPById_m(-2, $row->user_id)) / ($this->main_model->getMyPById_m(-2, $row->user_id))) * 100) . "%";
300 } else {
301 $mail_content = $mail_content . "0%";
302 }
303 $mail_content = $mail_content . "</h5>
304 </th>
305 </tr>
306 </table>
307 </div>
308
309 <div class='container standings' style='text-align:center !important;'>
310 <div class='jumbotron standings_distance margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #7d8700 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px;\">
311 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
312 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA DISTANZA</p>
313 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
314 <tbody>";
315
316 foreach ($this->main_model->distanceStandingMonth(-1)->result() as $standing) {
317 $mail_content = $mail_content . "<tr>
318 <td class=\"col-sm-2\" >" . $standing->nickname . "</td>
319 <td style='width:50px'></td>
320 <td class=\"col-sm-2\" >" . $standing->km . "</td>
321 </tr>";
322 }
323
324 $mail_content = $mail_content . "</tbody>
325 </table>
326 <br><br>";
327
328 if ($this->main_model->getDistanceStandingPositionById_m(-1, $row->user_id) != NULL && !empty($row->nickname)) {
329 foreach ($this->main_model->getDistanceStandingPositionById_m(-1, $row->user_id)->result() as $utente) {
330 $result = $utente->rank;
331 }
332 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . $result . "</h4>
333 </div>";
334 } else {
335 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
336
337 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
338 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
339 }
340
341 $mail_content = $mail_content . "</div>";
342 }
343
344 $mail_content = $mail_content . "<br>
345 <div class='jumbotron standings_time margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #ff9600 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px;\">
346 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
347 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA TEMPI</p>
348 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
349 <tbody>";
350
351 foreach ($this->main_model->timeStandingMonth(-1)->result() as $standingTime) {
352 $mail_content = $mail_content . "<tr>
353 <td class=\"col-sm-2\">" . $standingTime->nickname . "</td>
354 <td style='width:50px'></td>
355 <td class=\"col-sm-2\">" . $this->main_model->seconds($standingTime->seconds) . "</td>
356 </tr>";
357 }
358
359 $mail_content = $mail_content . "</tbody>
360 </table>
361 <br><br>";
362
363 if ($this->main_model->getTimeStandingPositionById_m(-1, $row->user_id) != NULL && !empty($row->nickname)) {
364 foreach ($this->main_model->getTimeStandingPositionById_m(-1, $row->user_id)->result() as $utenteTime) {
365 $resultTime = $utenteTime->rank;
366 }
367 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultTime . "</h4>
368 </div>";
369 } else {
370 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
371
372 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
373 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
374 }
375
376 $mail_content = $mail_content . "</div>";
377 }
378
379 $mail_content = $mail_content . "<br>
380 <div class='jumbotron standings_points margin-5 margin-top-10' style=\"margin:15px; display:inline-block; background-color: #ff3300 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important;border-radius: 6px;\">
381 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
382 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA PUNTI</p>
383 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
384 <tbody>";
385
386 //Foreach classifica punti
387 foreach ($this->main_model->pointsStandingMonth(-1)->result() as $standingPoints) {
388 $mail_content = $mail_content . "<tr>
389 <td class=\"col-sm-2\">" . $standingPoints->nickname . "</td>
390 <td style='width:50px'></td>
391 <td class=\"col-sm-2\">" . $standingPoints->tot_points . "</td>
392 </tr>";
393 }
394
395 $mail_content = $mail_content . "</tbody>
396 </table>
397 <br><br>";
398
399 if ($this->main_model->getPointsStandingPositionById_m(-1, $row->user_id) != NULL && !empty($row->nickname)) {
400 foreach ($this->main_model->getPointsStandingPositionById_m(-1, $row->user_id)->result() as $utentePoints) {
401 $resultPoints = $utentePoints->rank;
402 }
403 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultPoints . "</h4>
404 </div>";
405 } else {
406 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
407
408 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
409 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
410 }
411
412 $mail_content = $mail_content . "</div>";
413 }
414
415 $mail_content = $mail_content . "</div>
416 </div>
417 </div>
418 </body>
419 </html>";
420
421 echo $mail_content;
422 $this->email->message($mail_content);
423
424 echo $this->email->send();
425 echo $this->email->print_debugger();
426 sleep(1);
427
428 }
429 }
430
431
432 public function mailsenderWeekly()
433 {
434
435 $this->load->model('main_model');
436 $this->main_model->db_test_gamification();
437 $this->load->helper("url");
438 $setup_link = base_url() . "index.php/nickname_setup";
439
440 $utenti = $this->main_model->getAllUsersAndNicknames()->result();
441
442
443 $config = Array(
444 'protocol' => 'smtp',
445 'smtp_host' => 'ssl://smtp.gmail.com',
446 'smtp_port' => 465,
447 'smtp_user' => 'pepegatest@gmail.com',
448 'smtp_pass' => PASS,
449 'mailtype' => 'html',
450 'charset' => 'utf-8',
451 'wordwrap' => TRUE
452
453 );
454
455 $this->load->library('email', $config);
456
457 $this->email->set_mailtype("html");
458 $this->email->set_newline("\r\n");
459
460
461 //Calcolo periodo da inserire nella mail
462 $stringtime = strtotime(date("d M Y", strtotime("-1 weeks")));
463 $arrayDate = getdate($stringtime);
464
465 $firstday = $arrayDate["mday"] - $arrayDate["wday"];
466 $currentDate = strtotime(date("d M Y", strtotime("-1 weeks")));
467 $currentMonthAndYearIT = $this->timestamp_to_date_italian($currentDate);
468
469 if ($arrayDate["wday"] == 0) {
470 $firstday -= 6;
471 } else {
472 $firstday += 1;
473 }
474
475 $lastday = $arrayDate["mday"] - ($arrayDate["wday"] - 1) + 6;
476 foreach ($utenti as $row) {
477 $this->email->to('rick.espa@gmail.com');
478 $this->email->from('pepegatest@gmail.com', 'Classifica Settimanale');
479 $this->email->subject("Classifica Settimanale");
480
481 $mail_content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
482<html xmlns=3D\"http://www.w3.org/1999/xhtml\">
483 <head>
484 <meta http-equiv=3D\"content-type\" content=3D\"text/html; charset=3Dutf-8\"/>
485 <title>email</title>
486 <style>
487 .margin-5 {
488 margin: 5px;
489 }
490
491 .margin-top-10 {
492 margin-top: 10px;
493 }
494
495 .standings_points {
496 background-color: #ff3300 !important;
497 color: white !important;
498 display: inline-block;
499 width: 350px;
500 padding: 20px !important;
501 }
502 .standings_distance {
503 background-color: #7d8700 !important;
504 color: white !important;
505 display: inline-block;
506 width: 350px;
507 padding: 20px !important;
508 }
509
510 .standings_time {
511 background-color: #ff9600 !important;
512 color: white !important;
513 display: inline-block;
514 width: 350px;
515 padding: 20px !important;
516 }
517
518 .prog{
519 height:auto;
520 text-align:center;
521 }
522 .standings{
523 text-align:center !important;
524 }
525 </style>
526
527
528
529 </head>
530 <body>
531 <div dir=\"ltr\">
532 <div class='container' style=\" height:auto; text-align:center !important; \">
533 <h3 style=\"font-size: 28px !important;\">Riepilogo Settimanale" . "</h3>
534 <h4 style=\"font-size: 21px !important;\">" . "Dal " . $firstday . " " . $currentMonthAndYearIT . " al " . $lastday . " " . $currentMonthAndYearIT . "</h4>
535 <table style=\"text-align:center; margin-left:auto; margin-right:auto\">
536 <tr>
537 <th class='jumbotron standings_distance margin-5 margin-top-10'
538 style=' padding:10px; width:110px; background-color: #7d8700 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
539 <h6 style='text-align:right;'> km </h6>
540 <h4 style=\"font-size: 21px !important;\">";
541
542 $mail_content = $mail_content . $this->main_model->getMyKmById_w(-1, $row->user_id);
543 $mail_content = $mail_content . "</h4><h5>";
544
545 if ($this->main_model->getMyKmById_w(-2, $row->user_id) != 0) {
546 $mail_content = $mail_content . ceil((($this->main_model->getMyKmById_w(-1, $row->user_id) - $this->main_model->getMyKmById_w(-2, $row->user_id)) / ($this->main_model->getMyKmById_w(-2, $row->user_id))) * 100) . "%";
547 } else {
548 $mail_content = $mail_content . "0%";
549 }
550
551
552 $mail_content = $mail_content . "</h5>
553 </th>
554
555 <th class='jumbotron standings_time margin-5 margin-top-10'
556 style=' padding:10px; width:110px; background-color: #ff9600 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
557 <h6 style='text-align:right;'> hh:mm </h6>
558 <h4 style=\"font-size: 21px !important;\">";
559 $mail_content = $mail_content . $this->main_model->seconds($this->main_model->getMyTimeById_w(-1, $row->user_id));
560 $mail_content = $mail_content . "</h4><h5>";
561
562 if ($this->main_model->getMyTimeById_w(-2, $row->user_id) != 0) {
563 $mail_content = $mail_content . ceil((($this->main_model->getMyTimeById_w(-1, $row->user_id) - $this->main_model->getMyTimeById_w(-2, $row->user_id)) / ($this->main_model->getMyTimeById_w(-2, $row->user_id))) * 100) . "%";
564
565 } else {
566 $mail_content = $mail_content . "0%";
567 }
568
569 $mail_content = $mail_content . "</h5>
570 </th>
571
572 <th class='jumbotron standings_points margin-5 margin-top-10'
573 style=' padding:10px; width:110px; background-color: #ff3300 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
574 <h6 style='text-align:right;'> punti </h6>
575 <h4 style=\"font-size: 21px !important;\">";
576 $mail_content = $mail_content . $this->main_model->getMyPById_w(-1, $row->user_id);
577 $mail_content = $mail_content . "</h4><h5>";
578
579 if ($this->main_model->getMyPById_w(-2, $row->user_id) != 0) {
580 $mail_content = $mail_content . ceil((($this->main_model->getMyPById_w(-1, $row->user_id) - $this->main_model->getMyPById_w(-2, $row->user_id)) / ($this->main_model->getMyPById_w(-2, $row->user_id))) * 100) . "%";
581 } else {
582 $mail_content = $mail_content . "0%";
583 }
584 $mail_content = $mail_content . "</h5>
585 </th>
586 </tr>
587 </table>
588 </div>
589
590 <div class='container standings' style='text-align:center !important;'>
591 <div class='jumbotron standings_distance margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #7d8700 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px\">
592 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
593 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA DISTANZA</p>
594 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
595 <tbody>";
596
597 foreach ($this->main_model->distanceStandingWeek(-1)->result() as $standing) {
598 $mail_content = $mail_content . "<tr>
599 <td class=\"col-sm-2\" >" . $standing->nickname . "</td>
600 <td style='width:50px'></td>
601 <td class=\"col-sm-2\" >" . $standing->km . "</td>
602 </tr>";
603 }
604
605 $mail_content = $mail_content . "</tbody>
606 </table>
607 <br><br>";
608
609 if ($this->main_model->getDistanceStandingPositionById_w(-1, $row->user_id) != NULL && !empty($row->nickname)) {
610 foreach ($this->main_model->getDistanceStandingPositionById_w(-1, $row->user_id)->result() as $utente) {
611 $result = $utente->rank;
612 }
613 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . $result . "</h4>
614 </div>";
615 } else {
616 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
617
618 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
619 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
620 }
621
622 $mail_content = $mail_content . "</div>";
623 }
624
625 $mail_content = $mail_content . "<br>
626 <div class='jumbotron standings_time margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #ff9600 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px\">
627 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
628 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA TEMPI</p>
629 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
630 <tbody>";
631
632 foreach ($this->main_model->timeStandingWeek(-1)->result() as $standingTime) {
633 $mail_content = $mail_content . "<tr>
634 <td class=\"col-sm-2\">" . $standingTime->nickname . "</td>
635 <td style='width:50px'></td>
636 <td class=\"col-sm-2\">" . $this->main_model->seconds($standingTime->seconds) . "</td>
637 </tr>";
638 }
639
640 $mail_content = $mail_content . "</tbody>
641 </table>
642 <br><br>";
643
644 if ($this->main_model->getTimeStandingPositionById_w(-1, $row->user_id) != NULL && !empty($row->nickname)) {
645 foreach ($this->main_model->getTimeStandingPositionById_w(-1, $row->user_id)->result() as $utenteTime) {
646 $resultTime = $utenteTime->rank;
647 }
648 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultTime . "</h4>
649 </div>";
650 } else {
651 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
652
653 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
654 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
655 }
656
657 $mail_content = $mail_content . "</div>";
658 }
659
660 $mail_content = $mail_content . "<br>
661 <div class='jumbotron standings_points margin-5 margin-top-10' style=\"margin:15px; display:inline-block; background-color: #ff3300 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px\">
662 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
663 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA PUNTI</p>
664 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
665 <tbody>";
666
667 //Foreach classifica punti
668 foreach ($this->main_model->pointsStandingWeek(-1)->result() as $standingPoints) {
669 $mail_content = $mail_content . "<tr>
670 <td class=\"col-sm-2\">" . $standingPoints->nickname . "</td>
671 <td style='width:50px'></td>
672 <td class=\"col-sm-2\">" . $standingPoints->tot_points . "</td>
673 </tr>";
674 }
675
676 $mail_content = $mail_content . "</tbody>
677 </table>
678 <br><br>";
679
680 if ($this->main_model->getPointsStandingPositionById_w(-1, $row->user_id) != NULL && !empty($row->nickname)) {
681 foreach ($this->main_model->getPointsStandingPositionById_w(-1, $row->user_id)->result() as $utentePoints) {
682 $resultPoints = $utentePoints->rank;
683 }
684 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultPoints . "</h4>
685 </div>";
686 } else {
687 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
688
689 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
690 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
691 }
692
693 $mail_content = $mail_content . "</div>";
694 }
695
696 $mail_content = $mail_content . "</div>
697 </div>
698 </div>
699 </body>
700 </html>";
701
702 echo $mail_content;
703 $this->email->message($mail_content);
704
705 echo $this->email->send();
706 echo $this->email->print_debugger();
707 sleep(1);
708
709 }
710 }
711
712
713 public function mailsenderAnnually()
714 {
715 $this->load->model('main_model');
716 $this->main_model->db_test_gamification();
717 $this->load->helper("url");
718
719 $setup_link = base_url() . "index.php/nickname_setup";
720 $utenti = $this->main_model->getAllUsersAndNicknames()->result();
721
722
723 $config = Array(
724 'protocol' => 'smtp',
725 'smtp_host' => 'ssl://smtp.gmail.com',
726 'smtp_port' => 465,
727 'smtp_user' => 'pepegatest@gmail.com',
728 'smtp_pass' => PASS,
729 'mailtype' => 'html',
730 'charset' => 'utf-8',
731 'wordwrap' => TRUE
732
733 );
734
735 $this->load->library('email', $config);
736
737 $this->email->set_mailtype("html");
738 $this->email->set_newline("\r\n");
739
740 $newdate = date("Y", strtotime("-1 years"));
741 foreach ($utenti as $row) {
742 $this->email->to('rick.espa@gmail.com');
743 $this->email->from('pepegatest@gmail.com', 'Classifica Annuale');
744 $this->email->subject("Classifica Annuale");
745
746 $mail_content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
747<html xmlns=3D\"http://www.w3.org/1999/xhtml\">
748 <head>
749 <meta http-equiv=3D\"content-type\" content=3D\"text/html; charset=3Dutf-8\"/>
750 <title>email</title>
751 <style>
752 .margin-5 {
753 margin: 5px;
754 }
755
756 .margin-top-10 {
757 margin-top: 10px;
758 }
759
760 .standings_points {
761 background-color: #ff3300 !important;
762 color: white !important;
763 display: inline-block;
764 width: 350px;
765 padding: 20px !important;
766 }
767 .standings_distance {
768 background-color: #7d8700 !important;
769 color: white !important;
770 display: inline-block;
771 width: 350px;
772 padding: 20px !important;
773 }
774
775 .standings_time {
776 background-color: #ff9600 !important;
777 color: white !important;
778 display: inline-block;
779 width: 350px;
780 padding: 20px !important;
781 }
782
783 .prog{
784 height:auto;
785 text-align:center;
786 }
787 .standings{
788 text-align:center !important;
789 }
790 </style>
791
792
793
794 </head>
795 <body>
796 <div dir=\"ltr\">
797 <div class='container' style=\" height:auto; text-align:center !important; \">
798 <h3 style=\"font-size: 28px !important;\">Riepilogo Annuale" . "</h3>
799 <h4 style=\"font-size: 21px !important;\">" . "Relativo al " . $newdate . "</h4>
800 <table style=\"text-align:center; margin-left:auto; margin-right:auto\">
801 <tr>
802 <th class='jumbotron standings_distance margin-5 margin-top-10'
803 style=' padding:10px; width:110px; background-color: #7d8700 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
804 <h6 style='text-align:right;'> km </h6>
805 <h4 style=\"font-size: 21px !important;\">";
806
807 $mail_content = $mail_content . $this->main_model->getMyKmById_y(-1, $row->user_id);
808 $mail_content = $mail_content . "</h4><h5>";
809
810 if ($this->main_model->getMyKmById_y(-2, $row->user_id) != 0) {
811 $mail_content = $mail_content . ceil((($this->main_model->getMyKmById_y(-1, $row->user_id) - $this->main_model->getMyKmById_y(-2, $row->user_id)) / ($this->main_model->getMyKmById_y(-2, $row->user_id))) * 100) . "%";
812 } else {
813 $mail_content = $mail_content . "0%";
814 }
815
816
817 $mail_content = $mail_content . "</h5>
818 </th>
819
820 <th class='jumbotron standings_time margin-5 margin-top-10'
821 style=' padding:10px; width:110px; background-color: #ff9600 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
822 <h6 style='text-align:right;'> hh:mm </h6>
823 <h4 style=\"font-size: 21px !important;\">";
824 $mail_content = $mail_content . $this->main_model->seconds($this->main_model->getMyTimeById_y(-1, $row->user_id));
825 $mail_content = $mail_content . "</h4><h5>";
826
827 if ($this->main_model->getMyTimeById_y(-2, $row->user_id) != 0) {
828 $mail_content = $mail_content . ceil((($this->main_model->getMyTimeById_y(-1, $row->user_id) - $this->main_model->getMyTimeById_y(-2, $row->user_id)) / ($this->main_model->getMyTimeById_y(-2, $row->user_id))) * 100) . "%";
829
830 } else {
831 $mail_content = $mail_content . "0%";
832 }
833
834 $mail_content = $mail_content . "</h5>
835 </th>
836
837 <th class='jumbotron standings_points margin-5 margin-top-10'
838 style=' padding:10px; width:110px; background-color: #ff3300 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
839 <h6 style='text-align:right;'> punti </h6>
840 <h4 style=\"font-size: 21px !important;\">";
841 $mail_content = $mail_content . $this->main_model->getMyPById_y(-1, $row->user_id);
842 $mail_content = $mail_content . "</h4><h5>";
843
844 if ($this->main_model->getMyPById_y(-2, $row->user_id) != 0) {
845 $mail_content = $mail_content . ceil((($this->main_model->getMyPById_y(-1, $row->user_id) - $this->main_model->getMyPById_y(-2, $row->user_id)) / ($this->main_model->getMyPById_y(-2, $row->user_id))) * 100) . "%";
846 } else {
847 $mail_content = $mail_content . "0%";
848 }
849 $mail_content = $mail_content . "</h5>
850 </th>
851 </tr>
852 </table>
853 </div>
854
855 <div class='container standings' style='text-align:center !important;'>
856 <div class='jumbotron standings_distance margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #7d8700 !important; color: white !important; display: inline-block; width: 300px; padding: 20px !important; border-radius: 6px\">
857 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
858 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA DISTANZA</p>
859 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
860 <tbody>";
861
862 foreach ($this->main_model->distanceStandingYear(-1)->result() as $standing) {
863 $mail_content = $mail_content . "<tr>
864 <td class=\"col-sm-2\" >" . $standing->nickname . "</td>
865 <td style='width:50px'></td>
866 <td class=\"col-sm-2\" >" . $standing->km . "</td>
867 </tr>";
868 }
869
870 $mail_content = $mail_content . "</tbody>
871 </table>
872 <br><br>";
873
874 if ($this->main_model->getDistanceStandingPositionById_y(-1, $row->user_id) != NULL && !empty($row->nickname)) {
875 foreach ($this->main_model->getDistanceStandingPositionById_y(-1, $row->user_id)->result() as $utente) {
876 $result = $utente->rank;
877 }
878 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . $result . "</h4>
879 </div>";
880 } else {
881 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
882
883 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
884 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
885 }
886
887 $mail_content = $mail_content . "</div>";
888 }
889
890 $mail_content = $mail_content . "<br>
891 <div class='jumbotron standings_time margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #ff9600 !important; color: white !important;
892 display: inline-block; width: 300px; padding: 20px !important; border-radius: 6px\">
893 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
894 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA TEMPI</p>
895 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
896 <tbody>";
897
898 foreach ($this->main_model->timeStandingYear(-1)->result() as $standingTime) {
899 $mail_content = $mail_content . "<tr>
900 <td class=\"col-sm-2\">" . $standingTime->nickname . "</td>
901 <td style='width:50px'></td>
902 <td class=\"col-sm-2\">" . $this->main_model->seconds($standingTime->seconds) . "</td>
903 </tr>";
904 }
905
906 $mail_content = $mail_content . "</tbody>
907 </table>
908 <br><br>";
909
910 if ($this->main_model->getTimeStandingPositionById_y(-1, $row->user_id) != NULL && !empty($row->nickname)) {
911 foreach ($this->main_model->getTimeStandingPositionById_y(-1, $row->user_id)->result() as $utenteTime) {
912 $resultTime = $utenteTime->rank;
913 }
914 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultTime . "</h4>
915 </div>";
916 } else {
917 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
918
919 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
920 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
921 }
922
923 $mail_content = $mail_content . "</div>";
924 }
925
926 $mail_content = $mail_content . "<br>
927 <div class='jumbotron standings_points margin-5 margin-top-10' style=\"margin:15px; display:inline-block; background-color: #ff3300 !important; color: white !important;
928 display: inline-block; width: 300px; padding: 20px !important; border-radius: 6px\">
929 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
930 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA PUNTI</p>
931 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
932 <tbody>";
933
934 //Foreach classifica punti
935 foreach ($this->main_model->pointsStandingYear(-1)->result() as $standingPoints) {
936 $mail_content = $mail_content . "<tr>
937 <td class=\"col-sm-2\">" . $standingPoints->nickname . "</td>
938 <td style='width:50px'></td>
939 <td class=\"col-sm-2\">" . $standingPoints->tot_points . "</td>
940 </tr>";
941 }
942
943 $mail_content = $mail_content . "</tbody>
944 </table>
945 <br><br>";
946
947 if ($this->main_model->getPointsStandingPositionById_y(-1, $row->user_id) != NULL && !empty($row->nickname)) {
948 foreach ($this->main_model->getPointsStandingPositionById_y(-1, $row->user_id)->result() as $utentePoints) {
949 $resultPoints = $utentePoints->rank;
950 }
951 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultPoints . "</h4>
952 </div>";
953 } else {
954 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
955
956 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
957 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
958 }
959
960 $mail_content = $mail_content . "</div>";
961 }
962
963 $mail_content = $mail_content . "</div>
964 </div>
965 </div>
966 </body>
967 </html>";
968
969 echo $mail_content;
970 $this->email->message($mail_content);
971
972 echo $this->email->send();
973 echo $this->email->print_debugger();
974 sleep(1);
975
976 }
977 }
978
979
980 public function dbCreation()
981 {
982 $this->load->model('main_model');
983 echo "start\n\n";
984 $this->main_model->db_test_gamification();
985 $query1 = $this->db->query("select user_id, (distance/1000) as km, creationdate from workoutItem join user on user_id = item_user_id where creationdate > timestampadd(year, -3, current_timestamp()); ");
986 //mysqli_close();
987 $fp = fopen("points.txt", "w");
988 if (!$fp) die ("Errore nella operaione con il file");
989 $this->main_model->db_test_gamification_local();
990
991// $this->db->query("create table test_gamification_local.points(
992// user_id int,
993// points int,
994// data timestamp,
995// reason varchar(65)
996// );");
997 fprintf($fp, "drop table if exists test_gamification_local.points;\n\n");
998 fprintf($fp, "create table test_gamification_local.points(
999 user_id int,
1000 points int,
1001 data timestamp,
1002 reason varchar(65)
1003 );\n\n");
1004
1005 foreach ($query1->result() as $row) {
1006 $id = $row->user_id;
1007 $km = ceil($row->km);
1008 $punti_per_km = 100;
1009 $creationdate = date('Y-m-d', strtotime($row->creationdate));
1010 if ($km > 0)
1011 //$this->db->query("insert into test_gamification_local.points values($id, $km, '$creationdate', 'Per aver percorso $km km');");
1012 // fwrite($fp, "insert into test_gamification_local.points values($id, $km, '$creationdate', 'Per aver percorso $km km');");
1013 fprintf($fp, "insert into test_gamification_local.points values(%d, %d, '%s', 'Per aver percorso %d km');\n", $id, ($km * $punti_per_km), $creationdate, $km);
1014 }
1015 fclose($fp);
1016 echo "fine punti \n\n";
1017
1018 $this->main_model->db_test_gamification();
1019 $query2 = $this->db->query("select user_id from user where user_is_tester = 0 limit 0,7000");
1020
1021 $fp2 = fopen("nicks.txt", "w");
1022 if (!$fp2) die ("Errore nella operaione con il file");
1023 $this->main_model->db_test_gamification_local();
1024
1025 fprintf($fp2, "drop table if exists test_gamification_local.user;\n\n");
1026 fprintf($fp2, "create table test_gamification_local.user(
1027 `user_id` int(11) NOT NULL,
1028 `nickname` varchar(20) DEFAULT NULL,
1029 PRIMARY KEY (`user_id`),
1030 UNIQUE KEY `nickname` (`nickname`);\n\n");
1031 foreach ($query2->result() as $row2) {
1032 $id = $row2->user_id;
1033 $nick = "nick" . $id;
1034 fprintf($fp2, "insert into test_gamification_local.user values(%d, '%s');\n", $id, $nick);
1035 }
1036 fclose($fp2);
1037 echo "fine nick \n\n";
1038 }
1039
1040 public function outPutUsers()
1041 {
1042 $this->load->model('main_model');
1043 $this->main_model->db_test_gamification();
1044 $this->load->helper("url");
1045
1046 $stringtime = strtotime(date("d M Y", strtotime("-1 weeks")));
1047 $arrayDate = getdate($stringtime);
1048
1049 $firstday = $arrayDate["mday"] - $arrayDate["wday"];
1050
1051 if ($arrayDate["wday"] == 0) {
1052 $firstday -= 6;
1053 } else {
1054 $firstday += 1;
1055 }
1056
1057 echo $firstday;
1058
1059 $lastday = $arrayDate["mday"] - ($arrayDate["wday"] - 1) + 6;
1060
1061 echo $lastday;
1062
1063 $currentDate = strtotime(date("d M Y", strtotime("-1 weeks")));
1064 echo $this->timestamp_to_date_italian($currentDate);
1065
1066 echo "<br>";
1067 $currentMonthAndYearIT = $this->timestamp_to_date_italian($currentDate);
1068 echo "Dal " . $firstday . " " . $currentMonthAndYearIT . " al " . $lastday . " " . $currentMonthAndYearIT;
1069 }
1070
1071 function timestamp_to_date_italian($date)
1072 {
1073 $months = array(
1074 '01' => 'Gennaio',
1075 '02' => 'Febbraio',
1076 '03' => 'Marzo',
1077 '04' => 'Aprile',
1078 '05' => 'Maggio',
1079 '06' => 'Giugno',
1080 '07' => 'Luglio',
1081 '08' => 'Agosto',
1082 '09' => 'Settembre',
1083 '10' => 'Ottobre',
1084 '11' => 'Novembre',
1085 '12' => 'Dicembre');
1086
1087 list($day, $month, $year) = explode('-', date('d-m-Y', $date));
1088 return /*$day . ' ' .*/ $months[$month] . ' ' . $year;
1089
1090 }
1091
1092
1093 public function mailsenderMonthlyTEST()
1094 {
1095 session_start();
1096 $this->load->model('main_model');
1097 $this->main_model->db_test_gamification();
1098 $this->load->helper("url");
1099 $setup_link = base_url() . "index.php/nickname_setup";
1100
1101 $utenti = $this->main_model->getAllUsersAndNicknames()->result();
1102
1103
1104 $config = Array(
1105 'protocol' => 'smtp',
1106 'smtp_host' => 'ssl://smtp.gmail.com',
1107 'smtp_port' => 465,
1108 'smtp_user' => 'pepegatest@gmail.com',
1109 'smtp_pass' => PASS,
1110 'mailtype' => 'html',
1111 'charset' => 'utf-8',
1112 'wordwrap' => TRUE
1113
1114 );
1115
1116 $this->load->library('email', $config);
1117
1118 $this->email->set_mailtype("html");
1119 $this->email->set_newline("\r\n");
1120
1121 $newdate = date("M Y", strtotime("-1 months"));
1122 foreach ($utenti as $row) {
1123 if ($row->user_id == $_SESSION["ID"]) {
1124 $this->email->to('rick.espa@gmail.com');
1125 $this->email->from('pepegatest@gmail.com', 'Classifica Mensile');
1126 $this->email->subject("Classifica Mensile");
1127
1128 $mail_content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
1129<html xmlns=3D\"http://www.w3.org/1999/xhtml\">
1130 <head>
1131 <meta http-equiv=3D\"content-type\" content=3D\"text/html; charset=3Dutf-8\"/>
1132 <title>email</title>
1133 <style>
1134 .margin-5 {
1135 margin: 5px;
1136 }
1137
1138 .margin-top-10 {
1139 margin-top: 10px;
1140 }
1141
1142 .standings_points {
1143 background-color: #ff3300 !important;
1144 color: white !important;
1145 display: inline-block;
1146 width: 350px;
1147 padding: 20px !important;
1148 }
1149 .standings_distance {
1150 background-color: #7d8700 !important;
1151 color: white !important;
1152 display: inline-block;
1153 width: 350px;
1154 padding: 20px !important;
1155 }
1156
1157 .standings_time {
1158 background-color: #ff9600 !important;
1159 color: white !important;
1160 display: inline-block;
1161 width: 350px;
1162 padding: 20px !important;
1163 }
1164
1165 .prog{
1166 height:auto;
1167 text-align:center;
1168 }
1169 .standings{
1170 text-align:center !important;
1171 }
1172 </style>
1173
1174
1175
1176 </head>
1177 <body>
1178 <div dir=\"ltr\">
1179 <div class='container' style=\" height:auto; text-align:center !important; \">
1180 <h3 style=\"font-size: 28px !important;\">Riepilogo mensile" . "</h3>
1181 <h4 style=\"font-size: 21px !important;\">" . $newdate . "</h4>
1182 <table style=\"text-align:center; margin-left:auto; margin-right:auto\">
1183 <tr>
1184 <th class='jumbotron standings_distance margin-5 margin-top-10'
1185 style=' padding:10px; width:110px; background-color: #7d8700 !important; color: white !important; padding: 20px !important; border-radius: 6px;'>
1186 <h6 style='text-align:right;'> km </h6>
1187 <h4 style=\"font-size: 21px !important;\">";
1188
1189 $mail_content = $mail_content . $this->main_model->getMyKmById_m(-1, $row->user_id);
1190 $mail_content = $mail_content . "</h4><h5>";
1191
1192 if ($this->main_model->getMyKmById_m(-2, $row->user_id) != 0) {
1193 $mail_content = $mail_content . ceil((($this->main_model->getMyKmById_m(-1, $row->user_id) - $this->main_model->getMyKmById_m(-2, $row->user_id)) / ($this->main_model->getMyKmById_m(-2, $row->user_id))) * 100) . "%";
1194 } else {
1195 $mail_content = $mail_content . "0%";
1196 }
1197
1198
1199 $mail_content = $mail_content . "</h5>
1200 </th>
1201
1202 <th class='jumbotron standings_time margin-5 margin-top-10'
1203 style=' padding:10px; width:110px; background-color: #ff9600 !important; color: white !important; padding: 20px !important; border-radius: 6px;'>
1204 <h6 style='text-align:right;'> hh:mm </h6>
1205 <h4 style=\"font-size: 21px !important;\">";
1206 $mail_content = $mail_content . $this->main_model->seconds($this->main_model->getMyTimeById_m(-1, $row->user_id));
1207 $mail_content = $mail_content . "</h4><h5>";
1208
1209 if ($this->main_model->getMyTimeById_m(-2, $row->user_id) != 0) {
1210 $mail_content = $mail_content . ceil((($this->main_model->getMyTimeById_m(-1, $row->user_id) - $this->main_model->getMyTimeById_m(-2, $row->user_id)) / ($this->main_model->getMyTimeById_m(-2, $row->user_id))) * 100) . "%";
1211
1212 } else {
1213 $mail_content = $mail_content . "0%";
1214 }
1215
1216 $mail_content = $mail_content . "</h5>
1217 </th>
1218
1219 <th class='jumbotron standings_points margin-5 margin-top-10'
1220 style=' padding:10px; width:110px; background-color: #ff3300 !important; color: white !important; padding: 20px !important; border-radius: 6px;'>
1221 <h6 style='text-align:right;'> punti </h6>
1222 <h4 style=\"font-size: 21px !important;\">";
1223 $mail_content = $mail_content . $this->main_model->getMyPById_m(-1, $row->user_id);
1224 $mail_content = $mail_content . "</h4><h5>";
1225
1226 if ($this->main_model->getMyPById_m(-2, $row->user_id) != 0) {
1227 $mail_content = $mail_content . ceil((($this->main_model->getMyPById_m(-1, $row->user_id) - $this->main_model->getMyPById_m(-2, $row->user_id)) / ($this->main_model->getMyPById_m(-2, $row->user_id))) * 100) . "%";
1228 } else {
1229 $mail_content = $mail_content . "0%";
1230 }
1231 $mail_content = $mail_content . "</h5>
1232 </th>
1233 </tr>
1234 </table>
1235 </div>
1236
1237 <div class='container standings' style='text-align:center !important;'>
1238 <div class='jumbotron standings_distance margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #7d8700 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px;\">
1239 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1240 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA DISTANZA</p>
1241 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1242 <tbody>";
1243
1244 foreach ($this->main_model->distanceStandingMonth(-1)->result() as $standing) {
1245 $mail_content = $mail_content . "<tr>
1246 <td class=\"col-sm-2\" >" . $standing->nickname . "</td>
1247 <td style='width:50px'></td>
1248 <td class=\"col-sm-2\" >" . $standing->km . "</td>
1249 </tr>";
1250 }
1251
1252 $mail_content = $mail_content . "</tbody>
1253 </table>
1254 <br><br>";
1255
1256 if ($this->main_model->getDistanceStandingPositionById_m(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1257 foreach ($this->main_model->getDistanceStandingPositionById_m(-1, $row->user_id)->result() as $utente) {
1258 $result = $utente->rank;
1259 }
1260 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . $result . "</h4>
1261 </div>";
1262 } else {
1263 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1264
1265 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1266 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1267 }
1268
1269 $mail_content = $mail_content . "</div>";
1270 }
1271
1272 $mail_content = $mail_content . "<br>
1273 <div class='jumbotron standings_time margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #ff9600 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px;\">
1274 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1275 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA TEMPI</p>
1276 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1277 <tbody>";
1278
1279 foreach ($this->main_model->timeStandingMonth(-1)->result() as $standingTime) {
1280 $mail_content = $mail_content . "<tr>
1281 <td class=\"col-sm-2\">" . $standingTime->nickname . "</td>
1282 <td style='width:50px'></td>
1283 <td class=\"col-sm-2\">" . $this->main_model->seconds($standingTime->seconds) . "</td>
1284 </tr>";
1285 }
1286
1287 $mail_content = $mail_content . "</tbody>
1288 </table>
1289 <br><br>";
1290
1291 if ($this->main_model->getTimeStandingPositionById_m(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1292 foreach ($this->main_model->getTimeStandingPositionById_m(-1, $row->user_id)->result() as $utenteTime) {
1293 $resultTime = $utenteTime->rank;
1294 }
1295 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultTime . "</h4>
1296 </div>";
1297 } else {
1298 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1299
1300 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1301 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1302 }
1303
1304 $mail_content = $mail_content . "</div>";
1305 }
1306
1307 $mail_content = $mail_content . "<br>
1308 <div class='jumbotron standings_points margin-5 margin-top-10' style=\"margin:15px; display:inline-block; background-color: #ff3300 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important;border-radius: 6px;\">
1309 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1310 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA PUNTI</p>
1311 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1312 <tbody>";
1313
1314 //Foreach classifica punti
1315 foreach ($this->main_model->pointsStandingMonth(-1)->result() as $standingPoints) {
1316 $mail_content = $mail_content . "<tr>
1317 <td class=\"col-sm-2\">" . $standingPoints->nickname . "</td>
1318 <td style='width:50px'></td>
1319 <td class=\"col-sm-2\">" . $standingPoints->tot_points . "</td>
1320 </tr>";
1321 }
1322
1323 $mail_content = $mail_content . "</tbody>
1324 </table>
1325 <br><br>";
1326
1327 if ($this->main_model->getPointsStandingPositionById_m(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1328 foreach ($this->main_model->getPointsStandingPositionById_m(-1, $row->user_id)->result() as $utentePoints) {
1329 $resultPoints = $utentePoints->rank;
1330 }
1331 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultPoints . "</h4>
1332 </div>";
1333 } else {
1334 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1335
1336 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1337 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1338 }
1339
1340 $mail_content = $mail_content . "</div>";
1341 }
1342
1343 $mail_content = $mail_content . "</div>
1344 </div>
1345 </div>
1346 </body>
1347 </html>";
1348
1349 echo $mail_content;
1350 $this->email->message($mail_content);
1351
1352 echo $this->email->send();
1353 echo $this->email->print_debugger();
1354 sleep(1);
1355 }
1356 }
1357 }
1358
1359
1360 public function mailsenderWeeklyTEST()
1361 {
1362 session_start();
1363 $this->load->model('main_model');
1364 $this->main_model->db_test_gamification();
1365 $this->load->helper("url");
1366 $setup_link = base_url() . "index.php/nickname_setup";
1367
1368 $utenti = $this->main_model->getAllUsersAndNicknames()->result();
1369
1370
1371 $config = Array(
1372 'protocol' => 'smtp',
1373 'smtp_host' => 'ssl://smtp.gmail.com',
1374 'smtp_port' => 465,
1375 'smtp_user' => 'pepegatest@gmail.com',
1376 'smtp_pass' => PASS,
1377 'mailtype' => 'html',
1378 'charset' => 'utf-8',
1379 'wordwrap' => TRUE
1380
1381 );
1382
1383 $this->load->library('email', $config);
1384
1385 $this->email->set_mailtype("html");
1386 $this->email->set_newline("\r\n");
1387
1388
1389 //Calcolo periodo da inserire nella mail
1390 $stringtime = strtotime(date("d M Y", strtotime("-1 weeks")));
1391 $arrayDate = getdate($stringtime);
1392
1393 $firstday = $arrayDate["mday"] - $arrayDate["wday"];
1394 $currentDate = strtotime(date("d M Y", strtotime("-1 weeks")));
1395 $currentMonthAndYearIT = $this->timestamp_to_date_italian($currentDate);
1396
1397 if ($arrayDate["wday"] == 0) {
1398 $firstday -= 6;
1399 } else {
1400 $firstday += 1;
1401 }
1402
1403 $lastday = $arrayDate["mday"] - ($arrayDate["wday"] - 1) + 6;
1404 foreach ($utenti as $row) {
1405 if ($row->user_id == $_SESSION["ID"]) {
1406 $this->email->to('rick.espa@gmail.com');
1407 $this->email->from('pepegatest@gmail.com', 'Classifica Settimanale');
1408 $this->email->subject("Classifica Settimanale");
1409
1410 $mail_content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
1411<html xmlns=3D\"http://www.w3.org/1999/xhtml\">
1412 <head>
1413 <meta http-equiv=3D\"content-type\" content=3D\"text/html; charset=3Dutf-8\"/>
1414 <title>email</title>
1415 <style>
1416 .margin-5 {
1417 margin: 5px;
1418 }
1419
1420 .margin-top-10 {
1421 margin-top: 10px;
1422 }
1423
1424 .standings_points {
1425 background-color: #ff3300 !important;
1426 color: white !important;
1427 display: inline-block;
1428 width: 350px;
1429 padding: 20px !important;
1430 }
1431 .standings_distance {
1432 background-color: #7d8700 !important;
1433 color: white !important;
1434 display: inline-block;
1435 width: 350px;
1436 padding: 20px !important;
1437 }
1438
1439 .standings_time {
1440 background-color: #ff9600 !important;
1441 color: white !important;
1442 display: inline-block;
1443 width: 350px;
1444 padding: 20px !important;
1445 }
1446
1447 .prog{
1448 height:auto;
1449 text-align:center;
1450 }
1451 .standings{
1452 text-align:center !important;
1453 }
1454 </style>
1455
1456
1457
1458 </head>
1459 <body>
1460 <div dir=\"ltr\">
1461 <div class='container' style=\" height:auto; text-align:center !important; \">
1462 <h3 style=\"font-size: 28px !important;\">Riepilogo Settimanale" . "</h3>
1463 <h4 style=\"font-size: 21px !important;\">" . "Dal " . $firstday . " " . $currentMonthAndYearIT . " al " . $lastday . " " . $currentMonthAndYearIT . "</h4>
1464 <table style=\"text-align:center; margin-left:auto; margin-right:auto\">
1465 <tr>
1466 <th class='jumbotron standings_distance margin-5 margin-top-10'
1467 style=' padding:10px; width:110px; background-color: #7d8700 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
1468 <h6 style='text-align:right;'> km </h6>
1469 <h4 style=\"font-size: 21px !important;\">";
1470
1471 $mail_content = $mail_content . $this->main_model->getMyKmById_w(-1, $row->user_id);
1472 $mail_content = $mail_content . "</h4><h5>";
1473
1474 if ($this->main_model->getMyKmById_w(-2, $row->user_id) != 0) {
1475 $mail_content = $mail_content . ceil((($this->main_model->getMyKmById_w(-1, $row->user_id) - $this->main_model->getMyKmById_w(-2, $row->user_id)) / ($this->main_model->getMyKmById_w(-2, $row->user_id))) * 100) . "%";
1476 } else {
1477 $mail_content = $mail_content . "0%";
1478 }
1479
1480
1481 $mail_content = $mail_content . "</h5>
1482 </th>
1483
1484 <th class='jumbotron standings_time margin-5 margin-top-10'
1485 style=' padding:10px; width:110px; background-color: #ff9600 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
1486 <h6 style='text-align:right;'> hh:mm </h6>
1487 <h4 style=\"font-size: 21px !important;\">";
1488 $mail_content = $mail_content . $this->main_model->seconds($this->main_model->getMyTimeById_w(-1, $row->user_id));
1489 $mail_content = $mail_content . "</h4><h5>";
1490
1491 if ($this->main_model->getMyTimeById_w(-2, $row->user_id) != 0) {
1492 $mail_content = $mail_content . ceil((($this->main_model->getMyTimeById_w(-1, $row->user_id) - $this->main_model->getMyTimeById_w(-2, $row->user_id)) / ($this->main_model->getMyTimeById_w(-2, $row->user_id))) * 100) . "%";
1493
1494 } else {
1495 $mail_content = $mail_content . "0%";
1496 }
1497
1498 $mail_content = $mail_content . "</h5>
1499 </th>
1500
1501 <th class='jumbotron standings_points margin-5 margin-top-10'
1502 style=' padding:10px; width:110px; background-color: #ff3300 !important; color: white !important; padding: 20px !important; border-radius: 6px '>
1503 <h6 style='text-align:right;'> punti </h6>
1504 <h4 style=\"font-size: 21px !important;\">";
1505 $mail_content = $mail_content . $this->main_model->getMyPById_w(-1, $row->user_id);
1506 $mail_content = $mail_content . "</h4><h5>";
1507
1508 if ($this->main_model->getMyPById_w(-2, $row->user_id) != 0) {
1509 $mail_content = $mail_content . ceil((($this->main_model->getMyPById_w(-1, $row->user_id) - $this->main_model->getMyPById_w(-2, $row->user_id)) / ($this->main_model->getMyPById_w(-2, $row->user_id))) * 100) . "%";
1510 } else {
1511 $mail_content = $mail_content . "0%";
1512 }
1513 $mail_content = $mail_content . "</h5>
1514 </th>
1515 </tr>
1516 </table>
1517 </div>
1518
1519 <div class='container standings' style='text-align:center !important;'>
1520 <div class='jumbotron standings_distance margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #7d8700 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px\">
1521 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1522 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA DISTANZA</p>
1523 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1524 <tbody>";
1525
1526 foreach ($this->main_model->distanceStandingWeek(-1)->result() as $standing) {
1527 $mail_content = $mail_content . "<tr>
1528 <td class=\"col-sm-2\" >" . $standing->nickname . "</td>
1529 <td style='width:50px'></td>
1530 <td class=\"col-sm-2\" >" . $standing->km . "</td>
1531 </tr>";
1532 }
1533
1534 $mail_content = $mail_content . "</tbody>
1535 </table>
1536 <br><br>";
1537
1538 if ($this->main_model->getDistanceStandingPositionById_w(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1539 foreach ($this->main_model->getDistanceStandingPositionById_w(-1, $row->user_id)->result() as $utente) {
1540 $result = $utente->rank;
1541 }
1542 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . $result . "</h4>
1543 </div>";
1544 } else {
1545 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1546
1547 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1548 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1549 }
1550
1551 $mail_content = $mail_content . "</div>";
1552 }
1553
1554 $mail_content = $mail_content . "<br>
1555 <div class='jumbotron standings_time margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #ff9600 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px\">
1556 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1557 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA TEMPI</p>
1558 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1559 <tbody>";
1560
1561 foreach ($this->main_model->timeStandingWeek(-1)->result() as $standingTime) {
1562 $mail_content = $mail_content . "<tr>
1563 <td class=\"col-sm-2\">" . $standingTime->nickname . "</td>
1564 <td style='width:50px'></td>
1565 <td class=\"col-sm-2\">" . $this->main_model->seconds($standingTime->seconds) . "</td>
1566 </tr>";
1567 }
1568
1569 $mail_content = $mail_content . "</tbody>
1570 </table>
1571 <br><br>";
1572
1573 if ($this->main_model->getTimeStandingPositionById_w(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1574 foreach ($this->main_model->getTimeStandingPositionById_w(-1, $row->user_id)->result() as $utenteTime) {
1575 $resultTime = $utenteTime->rank;
1576 }
1577 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultTime . "</h4>
1578 </div>";
1579 } else {
1580 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1581
1582 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1583 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1584 }
1585
1586 $mail_content = $mail_content . "</div>";
1587 }
1588
1589 $mail_content = $mail_content . "<br>
1590 <div class='jumbotron standings_points margin-5 margin-top-10' style=\"margin:15px; display:inline-block; background-color: #ff3300 !important; color: white !important; display: inline-block; width: 350px; padding: 20px !important; border-radius: 6px\">
1591 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1592 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA PUNTI</p>
1593 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1594 <tbody>";
1595
1596 //Foreach classifica punti
1597 foreach ($this->main_model->pointsStandingWeek(-1)->result() as $standingPoints) {
1598 $mail_content = $mail_content . "<tr>
1599 <td class=\"col-sm-2\">" . $standingPoints->nickname . "</td>
1600 <td style='width:50px'></td>
1601 <td class=\"col-sm-2\">" . $standingPoints->tot_points . "</td>
1602 </tr>";
1603 }
1604
1605 $mail_content = $mail_content . "</tbody>
1606 </table>
1607 <br><br>";
1608
1609 if ($this->main_model->getPointsStandingPositionById_w(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1610 foreach ($this->main_model->getPointsStandingPositionById_w(-1, $row->user_id)->result() as $utentePoints) {
1611 $resultPoints = $utentePoints->rank;
1612 }
1613 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultPoints . "</h4>
1614 </div>";
1615 } else {
1616 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1617
1618 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1619 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1620 }
1621
1622 $mail_content = $mail_content . "</div>";
1623 }
1624
1625 $mail_content = $mail_content . "</div>
1626 </div>
1627 </div>
1628 </body>
1629 </html>";
1630
1631 echo $mail_content;
1632 $this->email->message($mail_content);
1633
1634 echo $this->email->send();
1635 echo $this->email->print_debugger();
1636 sleep(1);
1637
1638 }
1639 }
1640 }
1641
1642
1643 public function mailsenderAnnuallyTEST()
1644 {
1645 session_start();
1646 $this->load->model('main_model');
1647 $this->main_model->db_test_gamification();
1648 $this->load->helper("url");
1649
1650 $setup_link = base_url() . "index.php/nickname_setup";
1651 $utenti = $this->main_model->getAllUsersAndNicknames()->result();
1652
1653
1654 $config = Array(
1655 'protocol' => 'smtp',
1656 'smtp_host' => 'ssl://smtp.gmail.com',
1657 'smtp_port' => 465,
1658 'smtp_user' => 'pepegatest@gmail.com',
1659 'smtp_pass' => PASS,
1660 'mailtype' => 'html',
1661 'charset' => 'utf-8',
1662 'wordwrap' => TRUE
1663
1664 );
1665
1666 $this->load->library('email', $config);
1667
1668 $this->email->set_mailtype("html");
1669 $this->email->set_newline("\r\n");
1670
1671 $newdate = date("Y", strtotime("-1 years"));
1672
1673 foreach ($utenti as $row) {
1674 if ($row->user_id == $_SESSION["ID"]) {
1675 $this->email->to('rick.espa@gmail.com');
1676 $this->email->from('pepegatest@gmail.com', 'Classifica Annuale');
1677 $this->email->subject("Classifica Annuale");
1678
1679 $mail_content = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
1680<html xmlns=3D\"http://www.w3.org/1999/xhtml\">
1681 <head>
1682 <meta http-equiv=3D\"content-type\" content=3D\"text/html; charset=3Dutf-8\"/>
1683 <title>email</title>
1684 <style>
1685 .margin-5 {
1686 margin: 5px;
1687 }
1688
1689 .margin-top-10 {
1690 margin-top: 10px;
1691 }
1692
1693 .standings_points {
1694 background-color: #ff3300 !important;
1695 color: white !important;
1696 display: inline-block;
1697 width: 350px;
1698 padding: 20px !important;
1699 }
1700 .standings_distance {
1701 background-color: #7d8700 !important;
1702 color: white !important;
1703 display: inline-block;
1704 width: 350px;
1705 padding: 20px !important;
1706 }
1707
1708 .standings_time {
1709 background-color: #ff9600 !important;
1710 color: white !important;
1711 display: inline-block;
1712 width: 350px;
1713 padding: 20px !important;
1714 }
1715
1716 .prog{
1717 height:auto;
1718 text-align:center;
1719 }
1720 .standings{
1721 text-align:center !important;
1722 }
1723 </style>
1724
1725
1726
1727 </head>
1728 <body>
1729 <div dir=\"ltr\">
1730 <div class='container' style=\" height:auto; text-align:center !important; \">
1731 <h3 style=\"font-size: 28px !important;\">Riepilogo Annuale" . "</h3>
1732 <h4 style=\"font-size: 21px !important;\">" . "Relativo al " . $newdate . "</h4>
1733 <table style=\"text-align:center; margin-left:auto; margin-right:auto\">
1734 <tr>
1735 <th class='jumbotron standings_distance margin-5 margin-top-10'
1736 style=' padding:10px; width:110px; background-color: #7d8700 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
1737 <h6 style='text-align:right;'> km </h6>
1738 <h4 style=\"font-size: 21px !important;\">";
1739
1740 $mail_content = $mail_content . $this->main_model->getMyKmById_y(-1, $row->user_id);
1741 $mail_content = $mail_content . "</h4><h5>";
1742
1743 if ($this->main_model->getMyKmById_y(-2, $row->user_id) != 0) {
1744 $mail_content = $mail_content . ceil((($this->main_model->getMyKmById_y(-1, $row->user_id) - $this->main_model->getMyKmById_y(-2, $row->user_id)) / ($this->main_model->getMyKmById_y(-2, $row->user_id))) * 100) . "%";
1745 } else {
1746 $mail_content = $mail_content . "0%";
1747 }
1748
1749
1750 $mail_content = $mail_content . "</h5>
1751 </th>
1752
1753 <th class='jumbotron standings_time margin-5 margin-top-10'
1754 style=' padding:10px; width:110px; background-color: #ff9600 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
1755 <h6 style='text-align:right;'> hh:mm </h6>
1756 <h4 style=\"font-size: 21px !important;\">";
1757 $mail_content = $mail_content . $this->main_model->seconds($this->main_model->getMyTimeById_y(-1, $row->user_id));
1758 $mail_content = $mail_content . "</h4><h5>";
1759
1760 if ($this->main_model->getMyTimeById_y(-2, $row->user_id) != 0) {
1761 $mail_content = $mail_content . ceil((($this->main_model->getMyTimeById_y(-1, $row->user_id) - $this->main_model->getMyTimeById_y(-2, $row->user_id)) / ($this->main_model->getMyTimeById_y(-2, $row->user_id))) * 100) . "%";
1762
1763 } else {
1764 $mail_content = $mail_content . "0%";
1765 }
1766
1767 $mail_content = $mail_content . "</h5>
1768 </th>
1769
1770 <th class='jumbotron standings_points margin-5 margin-top-10'
1771 style=' padding:10px; width:110px; background-color: #ff3300 !important; color: white !important; padding: 20px !important; border-radius: 6px'>
1772 <h6 style='text-align:right;'> punti </h6>
1773 <h4 style=\"font-size: 21px !important;\">";
1774 $mail_content = $mail_content . $this->main_model->getMyPById_y(-1, $row->user_id);
1775 $mail_content = $mail_content . "</h4><h5>";
1776
1777 if ($this->main_model->getMyPById_y(-2, $row->user_id) != 0) {
1778 $mail_content = $mail_content . ceil((($this->main_model->getMyPById_y(-1, $row->user_id) - $this->main_model->getMyPById_y(-2, $row->user_id)) / ($this->main_model->getMyPById_y(-2, $row->user_id))) * 100) . "%";
1779 } else {
1780 $mail_content = $mail_content . "0%";
1781 }
1782 $mail_content = $mail_content . "</h5>
1783 </th>
1784 </tr>
1785 </table>
1786 </div>
1787
1788 <div class='container standings' style='text-align:center !important;'>
1789 <div class='jumbotron standings_distance margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #7d8700 !important; color: white !important; display: inline-block; width: 300px; padding: 20px !important; border-radius: 6px\">
1790 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1791 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA DISTANZA</p>
1792 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1793 <tbody>";
1794
1795 foreach ($this->main_model->distanceStandingYear(-1)->result() as $standing) {
1796 $mail_content = $mail_content . "<tr>
1797 <td class=\"col-sm-2\" >" . $standing->nickname . "</td>
1798 <td style='width:50px'></td>
1799 <td class=\"col-sm-2\" >" . $standing->km . "</td>
1800 </tr>";
1801 }
1802
1803 $mail_content = $mail_content . "</tbody>
1804 </table>
1805 <br><br>";
1806
1807 if ($this->main_model->getDistanceStandingPositionById_y(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1808 foreach ($this->main_model->getDistanceStandingPositionById_y(-1, $row->user_id)->result() as $utente) {
1809 $result = $utente->rank;
1810 }
1811 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . $result . "</h4>
1812 </div>";
1813 } else {
1814 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1815
1816 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1817 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1818 }
1819
1820 $mail_content = $mail_content . "</div>";
1821 }
1822
1823 $mail_content = $mail_content . "<br>
1824 <div class='jumbotron standings_time margin-5 margin-top-10 ' style=\"margin:15px; display:inline-block; background-color: #ff9600 !important; color: white !important;
1825 display: inline-block; width: 300px; padding: 20px !important; border-radius: 6px\">
1826 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1827 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA TEMPI</p>
1828 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1829 <tbody>";
1830
1831 foreach ($this->main_model->timeStandingYear(-1)->result() as $standingTime) {
1832 $mail_content = $mail_content . "<tr>
1833 <td class=\"col-sm-2\">" . $standingTime->nickname . "</td>
1834 <td style='width:50px'></td>
1835 <td class=\"col-sm-2\">" . $this->main_model->seconds($standingTime->seconds) . "</td>
1836 </tr>";
1837 }
1838
1839 $mail_content = $mail_content . "</tbody>
1840 </table>
1841 <br><br>";
1842
1843 if ($this->main_model->getTimeStandingPositionById_y(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1844 foreach ($this->main_model->getTimeStandingPositionById_y(-1, $row->user_id)->result() as $utenteTime) {
1845 $resultTime = $utenteTime->rank;
1846 }
1847 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultTime . "</h4>
1848 </div>";
1849 } else {
1850 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1851
1852 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1853 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1854 }
1855
1856 $mail_content = $mail_content . "</div>";
1857 }
1858
1859 $mail_content = $mail_content . "<br>
1860 <div class='jumbotron standings_points margin-5 margin-top-10' style=\"margin:15px; display:inline-block; background-color: #ff3300 !important; color: white !important;
1861 display: inline-block; width: 300px; padding: 20px !important; border-radius: 6px\">
1862 <h6 style=\"text-align:right\">Prime 10 posizioni</h6>
1863 <p style=\"text-align:center; font-size: 21px !important;\">CLASSIFICA PUNTI</p>
1864 <table class=\"table table-condensed table-hover\" style=\"text-align:center; margin-left:auto; margin-right:auto\">
1865 <tbody>";
1866
1867 //Foreach classifica punti
1868 foreach ($this->main_model->pointsStandingYear(-1)->result() as $standingPoints) {
1869 $mail_content = $mail_content . "<tr>
1870 <td class=\"col-sm-2\">" . $standingPoints->nickname . "</td>
1871 <td style='width:50px'></td>
1872 <td class=\"col-sm-2\">" . $standingPoints->tot_points . "</td>
1873 </tr>";
1874 }
1875
1876 $mail_content = $mail_content . "</tbody>
1877 </table>
1878 <br><br>";
1879
1880 if ($this->main_model->getPointsStandingPositionById_y(-1, $row->user_id) != NULL && !empty($row->nickname)) {
1881 foreach ($this->main_model->getPointsStandingPositionById_y(-1, $row->user_id)->result() as $utentePoints) {
1882 $resultPoints = $utentePoints->rank;
1883 }
1884 $mail_content = $mail_content . "<h4 style = \"font-size: 21px !important; text-align:center\">" . $resultPoints . "</h4>
1885 </div>";
1886 } else {
1887 $mail_content = $mail_content . "<h4 style=\"font-size: 21px !important; text-align:center\">" . "---" . "</h4>";
1888
1889 if (empty($row->nickname)) { //Se il nickname non è settato allora visualizzo il link.
1890 $mail_content = $mail_content . "<a href='" . $setup_link . "' style='text-align:center; color: #820097'><strong> Clicca qui per abilitare la classifica</strong></a>";
1891 }
1892
1893 $mail_content = $mail_content . "</div>";
1894 }
1895
1896 $mail_content = $mail_content . "</div>
1897 </div>
1898 </div>
1899 </body>
1900 </html>";
1901
1902 echo $mail_content;
1903 $this->email->message($mail_content);
1904
1905 echo $this->email->send();
1906 echo $this->email->print_debugger();
1907 sleep(1);
1908
1909 }
1910 }
1911 }
1912}
1913
1914?>