Merge branch 'MDL-36900-master' of git://github.com/FMCorz/moodle
[moodle.git] / theme / mymobile / layout / general.php
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/>.
17 /**
18  * General layout for the mymobile theme
19  *
20  * @package    theme
21  * @subpackage mymobile
22  * @copyright  John Stabinger
23  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24  */
26 // Get blocks?
27 $toblock = optional_param('mymobile_blocks', false, PARAM_BOOL);
28 // Get settings?
29 $toset = optional_param('mymobile_settings', false, PARAM_BOOL);
31 $mypagetype = $PAGE->pagetype;
32 $mylayoutype = $PAGE->pagelayout;
33 $mydevice = $PAGE->devicetypeinuse;
35 if (!empty($PAGE->theme->settings->colourswatch)) {
36     $showswatch = $PAGE->theme->settings->colourswatch;
37 } else {
38     $showswatch = 'light';
39 }
41 if ($showswatch == 'light') {
42     $dtheme = 'd';
43     $dthemeb = 'd';
44     $datatheme = 'data-theme="b"';
45     $databodytheme = 'data-theme="d"';
46 } else {
47     $dtheme = 'd';
48     $dthemeb = 'c';
49     $datatheme = 'data-theme="a"';
50     $databodytheme = '';
51 }
53 // Custom settings.
54 $hasshowmobileintro = (!empty($PAGE->theme->settings->showmobileintro));
56 if (!empty($PAGE->theme->settings->showfullsizeimages)) {
57     $hasithumb = $PAGE->theme->settings->showfullsizeimages;
58 } else {
59     $hasithumb = 'ithumb';
60 }
62 if (!empty($PAGE->theme->settings->showsitetopic)) {
63     $showsitetopic = $PAGE->theme->settings->showsitetopic;
64 } else {
65     $showsitetopic = 'topicnoshow';
66 }
68 if (!empty($PAGE->theme->settings->usetableview)) {
69     $showusetableview = $PAGE->theme->settings->usetableview;
70 } else {
71     $showusetableview = 'tabshow';
72 }
74 // TODO: Fix this hardcoding there are other course formats that peopleuse.
75 //       Probably changing to an appropriate regex will do.
76 if ($mypagetype == 'course-view-topics' || $mypagetype == 'course-view-weeks') {
77     // Jump to current topic only in course pages.
78     $jumptocurrent = 'true';
79 } else {
80     $jumptocurrent = 'false';
81 }
83 // Below sets a URL variable to use in some links.
84 $urlblocks = new moodle_url($PAGE->url, array('mymobile_blocks' => 'true'));
85 $urlsettings = new moodle_url($PAGE->url, array('mymobile_settings' => 'true'));
87 $hasheading = ($PAGE->heading);
88 $hasnavbar = (empty($PAGE->layout_options['nonavbar']) && $PAGE->has_navbar());
89 $hasfooter = (empty($PAGE->layout_options['nofooter']));
90 $hasmyblocks = $PAGE->blocks->region_has_content('myblocks', $OUTPUT);
92 $courseheader = $coursecontentheader = $coursecontentfooter = $coursefooter = '';
93 if (empty($PAGE->layout_options['nocourseheaderfooter'])) {
94     $courseheader = $OUTPUT->course_header();
95     $coursecontentheader = $OUTPUT->course_content_header();
96     if (empty($PAGE->layout_options['nocoursefooter'])) {
97         $coursecontentfooter = $OUTPUT->course_content_footer();
98         $coursefooter = $OUTPUT->course_footer();
99     }
102 $bodyclasses = array();
103 $bodyclasses[] = (string)$hasithumb;
104 $bodyclasses[] = (string)$showsitetopic;
105 // Add ithumb class to decide whether to show or hide images and site topic.
107 // TODO: Better illustrate preceedence.
108 $gowide = ($mydevice == 'default' && $showusetableview == 'tabshow' || $mydevice == 'tablet' && $showusetableview == 'tabshow');
109 if ($gowide) {
110     // Initialize column position choices.
111     mymobile_initialise_colpos($PAGE);
113 $usercol = (mymobile_get_colpos() == 'on');
115 $renderer = $PAGE->get_renderer('theme_mymobile');
117 echo $OUTPUT->doctype() ?>
118 <html id="mymobile" <?php echo $OUTPUT->htmlattributes() ?>>
119 <head>
120     <title><?php echo $PAGE->title ?></title>
121     <link rel="shortcut icon" href="<?php echo $OUTPUT->pix_url('favicon', 'theme')?>" />
122     <link rel="apple-touch-icon-precomposed" sizes="114x114" href="<?php echo $OUTPUT->pix_url('m2m2x', 'theme')?>" />
123     <link rel="apple-touch-icon-precomposed" sizes="72x72" href="<?php echo $OUTPUT->pix_url('m2m', 'theme')?>" />
124     <link rel="apple-touch-icon-precomposed" href="<?php echo $OUTPUT->pix_url('m2m', 'theme')?>" />
126     <meta name="description" content="<?php echo strip_tags(format_text($SITE->summary, FORMAT_HTML)) ?>" />
127     <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />
129     <?php echo $OUTPUT->standard_head_html() ?>
130 </head>
131 <body id="<?php p($PAGE->bodyid) ?>" class="<?php p($PAGE->bodyclasses.' '.join(' ', $bodyclasses)) ?>">
132     <?php echo $OUTPUT->standard_top_of_body_html() ?>
133     <div id="<?php p($PAGE->bodyid) ?>PAGE" data-role="page" class="generalpage <?php echo 'ajaxedclass '; p($PAGE->bodyclasses.' '.join(' ', $bodyclasses));  ?> <?php if ($hasmyblocks && $usercol) { echo 'has-myblocks'; } ?> " data-title="<?php p($SITE->shortname) ?>">
134         <!-- start header -->
135         <div id="page-header" data-role="header" <?php echo($datatheme);?> class="mymobileheader" data-position="fixed">
136             <h1><?php echo $PAGE->heading ?></h1>
137             <?php if (isloggedin() && $mypagetype != 'site-index') { ?>
138             <a class="ui-btn-right" data-icon="home" href="<?php p($CFG->wwwroot) ?>" data-iconpos="notext" data-ajax="false"><?php p(get_string('home')); ?></a>
139             <?php } else if (!isloggedin()) {
140                 echo $OUTPUT->login_info();
141             } ?>
142             <?php if (!empty($courseheader)) { ?>
143             <div data-role="course-header"><?php echo $courseheader; ?></div>
144             <?php } ?>
145             <!-- start navbar -->
146             <div data-role="navbar">
147                 <ul>
148                 <?php if (!$gowide && !$hasmyblocks && !$toblock && $mypagetype == "mod-quiz-attempt" || !$gowide && !$hasmyblocks && !$toblock && $mylayoutype != "incourse") { ?>
149                     <li><a data-theme="c" class="blockload" href="<?php echo $urlblocks->out(); ?>"><?php p(get_string('blocks')); ?></a></li>
150                 <?php } ?>
151                 <?php if (!$toset) { ?>
152                     <li><a data-theme="c" href="<?php echo $urlsettings->out(); ?>"><?php p(get_string('settings')); ?></a></li>
153                 <?php } ?>
154                 <?php if ($jumptocurrent == 'true' && !$toblock && !$toset) { ?>
155                     <li><a data-theme="c" class="jumptocurrent" href="#"><?php p(get_string('jump')); ?></a></li>
156                 <?php } ?>
157                 <?php if (isloggedin() && $hasnavbar) { ?>
158                     <li><?php echo $OUTPUT->navbar(); ?></li>
159                 <?php } ?>
160                 </ul>
161             </div>
162             <!-- end navbar -->
163         </div>
164         <!-- end header -->
166         <!-- main content -->
167         <div data-role="content" class="mymobilecontent" <?php echo $databodytheme; ?>>
168           <?php if($toset) {  // If we get the true, that means load/show settings only. ?>
169             <h2 class="jsets"><?php p(get_string('settings')); ?></h2>
170             <?php
171             // Load lang menu if available.
172             echo $OUTPUT->lang_menu();
173             ?>
174             <ul data-role="listview" data-theme="<?php echo $dthemeb;?>" data-dividertheme="<?php echo $dtheme;?>" data-inset="true" class="settingsul">
175                 <?php echo $renderer->settings_tree($PAGE->settingsnav); ?>
176             </ul>
177             <?php echo $OUTPUT->login_info(); ?>
178           <?php } ?>
180             <div class="content-primary">
181                 <div class="region-content <?php if ($toblock) { echo 'mobile_blocksonly'; } ?>" id="themains">
182                 <?php
183                 // Only show main content if we are not showing anything else.
184                 if (!$toblock && !$toset) { ?>
185                     <?php if ($hasshowmobileintro && $mypagetype == 'site-index') { ?>
186                         <?php echo $PAGE->theme->settings->showmobileintro; ?>
187                     <?php } ?>
188                     <?php echo $coursecontentheader; ?>
189                     <?php echo $OUTPUT->main_content(); ?>
190                     <?php echo $coursecontentfooter; ?>
191                 <?php } ?>
192                 </div>
193             </div>
195             <?php if ($gowide && $hasmyblocks && !$toset) {
196             // If we get the true, that means load/show blocks only for tablet views only. ?>
197             <div class="content-secondary">
198                 <div class="tablets">
199                     <h1><?php echo $PAGE->heading ?></h1>
200                     <span><?php echo $PAGE->course->summary; ?></span>
201                 </div>
203                 <?php if ($hasmyblocks) { ?>
204                 <div data-role="collapsible-set" data-theme="<?php echo $dthemeb;?>">
205                     <?php echo $OUTPUT->blocks_for_region('myblocks') ?>
206                 </div>
207                 <?php } ?>
209                 <?php if ($gowide && isloggedin() && !isguestuser()) { ?>
211                 <div data-role="collapsible" data-collapsed="false" <?php echo $datatheme;?> data-content-theme="<?php echo $dthemeb;?>" id="profcol">
212                     <h3><?php p(''.$USER->firstname.' '.$USER->lastname.''); ?></h3>
213                     <div class="ui-grid-a">
214                         <div class="ui-block-a">
215                             <?php echo html_writer::tag('div', $OUTPUT->user_picture($USER, array('size'=>80)), array('class'=>'userimg'));?>
216                         </div>
217                         <div class="ui-block-b">
218                             <a data-role="button" data-icon="home" href="<?php p($CFG->wwwroot) ?>/my/"><?php p(get_string('myhome')); ?></a>
219                             <a data-role="button" data-icon="info" href="<?php p($CFG->wwwroot) ?>/user/profile.php"><?php p(get_string('myprofile')); ?></a>
220                             <a data-role="button" data-icon="back" data-ajax="false" href="<?php p($CFG->wwwroot) ?>/login/logout.php"><?php p(get_string('logout')); ?></a>
221                         </div>
222                     </div>
223                 </div>
225                 <div data-role="fieldcontain" id="sliderdiv">
226                     <label for="slider"><?php p(get_string('mtoggle', 'theme_mymobile')); ?>:</label>
227                     <select name="slider" class="slider" data-role="slider" id="slider">
228                         <option value="on">On</option>
229                         <option value="off">Off</option>
230                     </select>
231                 </div>
233                 <?php } else if (!isloggedin() || isguestuser()) { ?>
234                 <a data-role="button" <?php echo $datatheme;?> data-ajax="false" href="<?php p($CFG->wwwroot) ?>/login/index.php"><?php p(get_string('login')); ?></a>
235                  <?php } ?>
236             </div>
237             <?php } ?>
239             <?php
240             if ($toblock && !$gowide) {
241                 // Regular block load for phones + handhelds.
242                 if ($hasmyblocks) {
243                     ?><div class="headingwrap ui-bar-<?php echo $dtheme;?> ui-footer jsetsbar">
244                         <h2 class="jsets ui-title"><?php p(get_string('blocks')); ?></h2>
245                     </div>
246                     <div data-role="collapsible-set"><?php echo $OUTPUT->blocks_for_region('myblocks') ?></div><?php
247                 }
248             }
249             ?>
250         </div>
251         <!-- end main content -->
253         <!-- start footer -->
254         <?php if (!empty($coursefooter)) { ?>
255         <div data-role="course-footer"><?php echo $coursefooter; ?></div>
256         <?php } ?>
258         <div id="page-footer">
259             <div data-role="footer" class="mobilefooter" <?php echo $datatheme;?>>
260                 <div data-role="navbar" class="jnav" >
261                     <ul>
262                         <li><a id="mycal" class="callink" href="<?php p($CFG->wwwroot) ?>/calendar/view.php" data-icon="info" data-iconpos="top" ><?php p(get_string('calendar', 'calendar')); ?></a></li>
263                         <?php if (!empty($CFG->messaging)) { ?>
264                         <li><a id="mymess" href="<?php p($CFG->wwwroot) ?>/message/index.php" data-iconpos="top" data-icon="mymessage" ><?php p(get_string('messages', 'message')); ?></a></li>
265                         <?php } ?>
266                         <?php if ($mypagetype != 'site-index') { ?>
267                         <li><a href="#" data-inline="true" data-role="button" data-iconpos="top" data-icon="arrow-u" id="uptotop"><?php p(get_string('up')); ?></a></li>
268                         <?php } ?>
269                     </ul>
270                 </div>
271             </div>
273             <div id="underfooter">
274                 <?php
275                 echo $OUTPUT->login_info_footer();
276                 echo '<div class="noajax">';
277                 echo $OUTPUT->standard_footer_html();
278                 echo '</div>';
279                 ?>
280             </div>
281         </div>
282         <!-- end footer -->
283         <!-- empty divs with info for the JS to use -->
284         <div id="<?php echo sesskey(); ?>" class="mobilesession"></div>
285         <div id="<?php p($CFG->wwwroot); ?>" class="mobilesiteurl"></div>
286         <div id="<?php echo $dtheme;?>" class="datatheme"></div>
287         <div id="<?php echo $dthemeb;?>" class="datathemeb"></div>
288         <!-- end js divs -->
290         <?php echo $OUTPUT->standard_end_of_body_html() ?>
291     </div><!-- ends page -->
292 </body>
293 </html>