Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Prints an instance of mod_custommailing.
19
 *
20
 * @package    mod_custommailing
21
 * @author     olivier@cblue.be
22
 * @copyright  2021 CBlue SPRL
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
use mod_custommailing\Mailing;
27
 
28
require_once __DIR__ . '/../../config.php';
29
 
30
global $CFG, $DB, $PAGE, $OUTPUT;
31
 
32
require_once $CFG->dirroot . '/mod/custommailing/lib.php';
33
require_once $CFG->dirroot . '/mod/custommailing/mailing_form.php';
34
 
35
$id = required_param('id', PARAM_INT);
36
 
37
[$course, $cm] = get_course_and_cm_from_cmid($id, 'custommailing');
38
$custommailing = $DB->get_record("custommailing", ['id' => $cm->instance]);
39
$context = context_module::instance($cm->id);
40
 
41
require_login($course, false, $cm);
42
require_capability('mod/custommailing:manage', $context);
43
 
44
$url = new moodle_url('/mod/custommailing/view.php', ['id' => $cm->id]);
45
 
46
$PAGE->set_url($url);
47
$PAGE->set_title(format_string($course->shortname . ': ' . $custommailing->name));
48
$PAGE->set_heading(format_string($course->fullname));
49
$PAGE->set_context($context);
50
 
51
$mailings = Mailing::getAll($custommailing->id);
52
$activities = custommailing_get_activities(true);
53
 
54
echo $OUTPUT->header();
55
echo $OUTPUT->heading(format_string($custommailing->name));
56
 
57
echo '<hr>';
58
echo '<a class="btn btn-primary" href="' . (new moodle_url('/mod/custommailing/upsert.php', ['id' => $id]))->out(false) . '">' . get_string('createnewmailing', 'mod_custommailing') . '</a>';
59
echo '<hr>';
60
echo '<div id="mailingsList">';
61
foreach ($mailings as $mailing) {
62
    $mailing->mailingmodestr = '';
63
    if ($mailing->mailingmode == MAILING_MODE_FIRSTLAUNCH) {
64
        $mailing->mailingmodestr = get_string('atfirstlaunch', 'mod_custommailing');
65
    } elseif ($mailing->mailingmode == MAILING_MODE_REGISTRATION) {
66
        $mailing->mailingmodestr = get_string('atcourseenrol', 'mod_custommailing');
67
    } elseif ($mailing->mailingmode == MAILING_MODE_COMPLETE) {
68
        $mailing->mailingmodestr = get_string('atactivitycompleted', 'mod_custommailing');
69
    } elseif ($mailing->mailingmode == MAILING_MODE_DAYSFROMINSCRIPTIONDATE) {
70
        $mailing->mailingmodestr = $mailing->mailingdelay . ' ' . get_string('daysafter', 'mod_custommailing') . ' ' . get_string('courseenroldate', 'mod_custommailing');
71
    } elseif ($mailing->mailingmode == MAILING_MODE_DAYSFROMLASTCONNECTION) {
72
        $mailing->mailingmodestr = $mailing->mailingdelay . ' ' . get_string('daysafter', 'mod_custommailing') . ' ' . get_string('courselastaccess', 'mod_custommailing');
73
    } elseif ($mailing->mailingmode == MAILING_MODE_DAYSFROMFIRSTLAUNCH) {
74
        $mailing->mailingmodestr = $mailing->mailingdelay . ' ' . get_string('daysafter', 'mod_custommailing') . ' ' . get_string('firstlaunch', 'mod_custommailing');
75
    } elseif ($mailing->mailingmode == MAILING_MODE_DAYSFROMLASTLAUNCH) {
76
        $mailing->mailingmodestr = $mailing->mailingdelay . ' ' . get_string('daysafter', 'mod_custommailing') . ' ' . get_string('lastlaunch', 'mod_custommailing');
77
    }
78
    echo
79
        '<div class="card">
80
           <div class="card-header" id="mailing_' . $mailing->id . '">
81
             <h5 class="mb-0">
82
               <div data-toggle="collapse" data-target="#mailing_' . $mailing->id . '_content" aria-expanded="false" aria-controls="mailing_' . $mailing->id . '_content">
83
                 <strong>' . $mailing->mailingname . '</strong> (#' . $mailing->id . ')
84
                 <div class="pull-right">
85
                   <span class="disabled btn btn-sm ' . ($mailing->mailingstatus == MAILING_STATUS_ENABLED ? 'btn-success' : 'btn-warning') . '">' .
86
                    ($mailing->mailingstatus == MAILING_STATUS_ENABLED ? get_string('enabled', 'mod_custommailing') : get_string('disabled', 'mod_custommailing')) .
87
                  '</span>
88
                   <a class="btn btn-sm btn-info " href="' . (new moodle_url('/mod/custommailing/upsert.php', ['id' => $id, 'mailingid' => $mailing->id]))->out(false) . '">' . get_string('edit') . '</a>
89
                   <a class="btn btn-sm btn-danger " href="' . (new moodle_url('/mod/custommailing/delete.php', ['id' => $id, 'mailingid' => $mailing->id]))->out(false) . '">' . get_string('delete') . '</a>
90
                 </div>
91
                </div>
92
             </h5>
93
           </div>
94
 
95
           <div id="mailing_' . $mailing->id . '_content" class="collapse" aria-labelledby="mailing_' . $mailing->id . '" data-parent="#mailingsList">
96
             <div class="card-body">
97
                <p><strong>' . get_string('custommailingname', 'custommailing') . '</strong> : ' . $mailing->mailingname . '</p>';
98
    if (!empty($mailing->customcertmoduleid)) {
99
        echo '<p><strong>' . get_string('targetmoduleid', 'custommailing') . '</strong> : ' . custommailing_getCustomcert($mailing->customcertmoduleid)->name . ' </p>';
100
        $mailing->mailingmodestr = get_string('customcert_help', 'custommailing');
101
    } elseif (empty($mailing->targetmoduleid)) {
102
        echo    '<p><strong>' . get_string('targetmoduleid', 'custommailing') . '</strong> : - </p>';
103
    } else {
104
        echo    '<p><strong>' . get_string('targetmoduleid', 'custommailing') . '</strong> : ' . (isset($activities[$mailing->targetmoduleid]) ? $activities[$mailing->targetmoduleid] : 'not found') . '</p>';
105
    }
106
    echo        '<p><strong>' . get_string('sendmailing', 'custommailing') . '</strong> : ' . $mailing->mailingmodestr . '</p>
107
                <p><strong>' . get_string('mailingsubject', 'custommailing') . '</strong> : ' . $mailing->mailingsubject . '</p>
108
                <p><strong>' . get_string('mailingcontent', 'custommailing') . '</strong> : ' . $mailing->mailingcontent . '</p>
109
                <p><strong>' . get_string('timecreated', 'custommailing') . '</strong> : ' . userdate($mailing->timecreated) . '</p>
110
                <p><strong>' . get_string('timemodified', 'custommailing') . '</strong> : ' . userdate($mailing->timemodified) . '</p>
111
                ';
112
    echo     '</div>
113
           </div>
114
        </div>';
115
}
116
echo '</div>'; // mailingsList
117
echo '<hr>';
118
echo '<a class="btn btn-primary" href="' . (new moodle_url('/mod/custommailing/logs.php', ['id' => $id]))->out(false) . '">' . get_string('logtable', 'mod_custommailing') . '</a>';
119
 
120
echo $OUTPUT->footer();