move code up one directory
[atutor.git] / themes / default / photos / pa_albums.tmpl.php
1 <div id="uploader-contents">
2         <!-- Photo album options and page numbers -->
3         <?php if ($this->action_permission || $this->album_info['type_id']==AT_PA_TYPE_COURSE_ALBUM): ?>
4         <div class="add_photo">         
5                 <div class="toggle_uploader">
6                         <input type="button" id="upload_manager" name="upload_manager" value="<?php echo _AT('pa_open_upload_manager'); ?>" onclick="toggleUploadManager()" class="button" />
7                         <input type="hidden" id="upload_manager_toggle" value="1" />                    
8                 </div>
9
10                 <div class="input-form" id="ajax_uploader">
11                         <div class="row" id="upload_button_div">
12                                 <p name="top"><?php echo _AT('pa_upload_blurb');?></p>
13                                 <p class="memory_usage"><?php echo _AT('pa_memory_usage').': '. number_format($this->memory_usage, 2) .'/ '. $this->allowable_memory_usage . ' ' . _AT('mb'); ?></p>
14                                 <label for="add_more_photos" id="upload_button"><?php echo _AT('pa_add_more_photos'); ?></label>
15                         </div>                  
16                         <div class="row" id="files_pending" style="display:none;">
17                                 <img src="<?php echo AT_PA_BASENAME; ?>images/loading.gif" alt="loading" title="loading"/>
18                                 <span></span>
19                         </div>
20                         <div class="row">
21                                 <ul class="files"></ul>
22                         </div>
23                         <div class="row" >
24                                 <input id="files_done" disabled="disabled" type="button" value="<?php echo _AT("upload"); ?>" class="button" onclick="window.location.reload();" />
25                         </div>
26                 </div>
27         </div>
28         <?php endif; //action permission?>
29
30         <div class="album_panel">
31                 <div class="topbar">                    
32                         <?php if($this->num_rows > AT_PA_PHOTOS_PER_PAGE):  ?>
33                         <div class="paginator">
34                                 <?php print_paginator($this->page, $this->num_rows, 'id='.$this->album_info['id'], AT_PA_PHOTOS_PER_PAGE, AT_PA_PAGE_WINDOW);  ?>
35                         </div>
36                         <?php endif; ?>
37                 </div>
38                 <?php if(!empty($this->photos)): ?>
39                 <!-- loop through this -->
40                 <?php foreach($this->photos as $key=>$photo): ?>
41                 <div class="photo_frame">
42                         <a href="<?php echo AT_PA_BASENAME.'photo.php?pid='.$photo['id'].SEP.'aid='.$this->album_info['id'];?>"><img src="<?php echo AT_PA_BASENAME.'get_photo.php?aid='.$this->album_info['id'].SEP.'pid='.$photo['id'].SEP.'ph='.getPhotoFilePath($photo['id'], '', $photo['created_date']);?>" title="<?php echo AT_print($photo['description'], 'photos.description'); ?>" alt="<?php echo AT_print($photo['alt_text'], 'photos.alt_text');?>" /></a>
43                 </div>
44                 <?php endforeach; ?>
45                 <!-- end loop -->
46                 <div class="album_description">
47                         <p><?php if($this->album_info['location']!='') echo _AT('location').': '.AT_print($this->album_info['location'], 'photo_albums.location') .'<br/>';?>  
48                         <?php echo AT_print($this->album_info['description'], 'photo_albums.description');?></p>
49                 </div>          
50                 <?php else: ?>
51                 <div class="edit_photo_box">
52                         <p><?php echo _AT('pa_no_photos'); ?></p>
53                 </div>
54                 <?php endif; ?>
55                 <!-- page numbers -->
56                 <div class="topbar">
57                         <?php if($this->num_rows > AT_PA_PHOTOS_PER_PAGE):  ?>
58                         <div class="paginator">
59                                 <?php print_paginator($this->page, $this->num_rows, 'id='.$this->album_info['id'], AT_PA_PHOTOS_PER_PAGE, AT_PA_PAGE_WINDOW);  ?>
60                         </div>
61                         <?php endif; ?>
62                 </div>
63         </div>  
64
65         <!-- comments -->
66         <div class="comment_panel">
67                 <div class="comment_feeds">
68                         <?php if (!empty($this->comments)): ?>
69                         <?php foreach($this->comments as $k=>$comment_array): ?>
70                                 <div class="comment_box" id="comment_box">
71                                         <!-- TODO: Profile link and img -->
72                                         <?php if ($this->action_permission || $comment_array['member_id']==$_SESSION['member_id']): ?>
73                                         <div class="flc-inlineEditable">
74                                                 <strong><a href="profile.php?id=<?php echo $comment_array['member_id'];?>"><?php echo AT_print(get_display_name($comment_array['member_id']), 'members.full_name'); ?></a></strong>
75                                                 <span class="flc-inlineEdit-text" id="<?php echo $comment_array['id'];?>" ><?php echo AT_print($comment_array['comment'], 'photo_albums.comment');?></span>
76                                         </div>
77                                         <?php else: ?>
78                                         <div>
79                                                 <strong><a href="profile.php?id=<?php echo $comment_array['member_id'];?>"><?php echo AT_print(get_display_name($comment_array['member_id']), 'members.full_name'); ?></a></strong>
80                                                 <?php echo htmlentities_utf8($comment_array['comment'], true);?>
81                                         </div>
82                                         <?php endif; ?>
83                                         <div class="comment_actions">
84                                                 <!-- TODO: if author, add in-line "edit" -->
85                                                 <?php echo AT_date(_AT('forum_date_format'), $comment_array['created_date'], AT_DATE_MYSQL_DATETIME);?>
86                                                 <?php if ($this->action_permission || $comment_array['member_id']==$_SESSION['member_id']): ?>
87                                                 <a href="<?php echo AT_PA_BASENAME.'delete_comment.php?aid='.$this->album_info['id'].SEP.'comment_id='.$comment_array['id']?>"><?php echo _AT('delete');?></a>
88                                                 <?php endif; ?>
89                                         </div>
90                                 </div>
91                         <?php endforeach; endif;?>
92                         <!-- TODO: Add script to check, comment cannot be empty. -->
93                         <div>
94                                 <form action="<?php echo AT_PA_BASENAME;?>addComment.php" method="post" class="input-form">
95                                         <div class="row"><label for="comments"><?php echo _AT('comments');?></label></div>
96                                         <div class="row"><textarea name="comment" id="comment_template" onclick="jQuery(this).hide();c=jQuery('#comment');c.show();c.focus();" onkeyup="jQuery(this).hide();c=jQuery('#comment');c.show();c.focus();"><?php echo _AT('pa_write_a_comment'); ?></textarea></div>
97                                         <div class="row"><textarea name="comment" id="comment" style="display:none;"></textarea></div>
98                                         <div class="row">
99                                                 <input type="hidden" name="aid" value="<?php echo $this->album_info['id'];?>" />
100                                                 <input type="submit" name="submit" value="<?php echo _AT('comment');?>" class="button"/>
101                                         </div>
102                                 </form>
103                         </div>
104                 </div>          
105
106                 <?php if($this->action_permission): ?>
107                 <div class="photo_actions">
108                         <a href="<?php echo AT_PA_BASENAME.'edit_album.php?id='.$this->album_info['id']; ?>" class="pa_tool_link"><img src="<?php echo $_base_href; ?>themes/<?php echo $_SESSION['prefs']['PREF_THEME']; ?>/images/edit.gif" alt="" border="0"  class="pa_tool_image"/><?php echo _AT('pa_edit_album'); ?></a><br/>
109                 </div>
110                 <?php endif; ?>
111         </div>
112 </div>
113
114
115 <script type="text/javascript">
116 //<![CDATA[
117 /* Fluid inline editor */
118 jQuery(document).ready(function () {
119         //the ATutor undo function
120         var undo = function (that, targetContainer) {
121                 var markup = "<span class='flc-undo' aria-live='polite' aria-relevant='all' role='region'>" +
122                         "<span class='flc-undo-undoContainer' role='button'><a href='#' class='flc-undo-undoControl'>[<?php echo _AT('pa_undo'); ?>]</a></span>" +
123                         "<span class='flc-undo-redoContainer' role='button'><a href='#' class='flc-undo-redoControl'>[<?php echo _AT('pa_redo'); ?>]</a></span>" +
124                         "</span>";
125                 var markupNode = jQuery(markup);
126                 targetContainer.append(markupNode);
127                 return markupNode;
128         };
129         var pa_click_here_to_edit = '<?php echo _AT("pa_click_here_to_edit"); ?>';
130         var pa_click_item_to_edit = '<?php echo _AT("pa_click_item_to_edit"); ?>';
131
132         fluid.inlineEdits(".comment_feeds", {
133                 componentDecorators: {
134                         type: "fluid.undoDecorator",
135                         options: {
136                                 renderer: undo
137                         }
138                 },
139                 defaultViewText: pa_click_here_to_edit,
140                 useTooltip: true,
141                 tooltipText: pa_click_item_to_edit, 
142                 listeners: {
143                         modelChanged: function(model, oldModel, source){
144                                 /* for undo/redo model change */
145                                 if (model != oldModel && source != undefined){
146                                         commentID = source.component.locate("text").attr("id");
147                                         rtn = jQuery.post("<?php echo $_base_path. AT_PA_BASENAME.'edit_comment.php';?>", 
148                                                 {"submit":"submit",
149                                                  "aid":<?php echo $this->album_info['id'];?>, 
150                                                  "cid":commentID, 
151                                                  "comment":model.value},
152                                                   function(data){}, 
153                                                   "json");
154                                 }
155                         },
156                         afterFinishEdit : function (newValue, oldValue, editNode, viewNode) {
157                                 if (newValue != oldValue){
158                                         rtn = jQuery.post("<?php echo $_base_path. AT_PA_BASENAME.'edit_comment.php';?>", 
159                                                         {"submit":"submit",
160                                                          "aid":<?php echo $this->album_info['id'];?>, 
161                                                          "cid":viewNode.id, 
162                                                          "comment":newValue},
163                                                           function(data){}, 
164                                                           "json");
165                                 }
166                         }
167                 }
168         });
169 });
170
171 /* Ajax Uploader */
172 <?php if ($this->action_permission || $this->album_info['type_id']==AT_PA_TYPE_COURSE_ALBUM): ?>
173 var upload_pending  = 0; //counter for pending files
174 var ajax_upload = new AjaxUpload('upload_button', {
175   // Location of the server-side upload script
176   // NOTE: You are not allowed to upload files to another domain
177   action: '<?php echo $_base_path. AT_PA_BASENAME; ?>albums.php',
178   // File upload name
179   name: 'photo',
180   // Title 
181   title: '<?php echo _AT("pa_add_more_photos"); ?>',
182   // Additional data to send
183   data: {
184     upload : 'ajax',
185     id : '<?php echo $this->album_info['id'];?>'
186   },
187   // Submit file after selection
188   autoSubmit: true,
189   // The type of data that you're expecting back from the server.
190   // HTML (text) and XML are detected automatically.
191   // Useful when you are using JSON data as a response, set to "json" in that case.
192   // Also set server response type to text/html, otherwise it will not work in IE6
193   responseType: false,
194   // Fired after the file is selected
195   // Useful when autoSubmit is disabled
196   // You can return false to cancel upload
197   // @param file basename of uploaded file
198   // @param extension of that file
199   onChange: function(file, extension){},
200   // Fired before the file is uploaded
201   // You can return false to cancel upload
202   // @param file basename of uploaded file
203   // @param extension of that file
204   onSubmit: function(file, extension) {
205           upload_pending++;
206           if (upload_pending > 0){
207                 jQuery('#files_pending').show();
208                 jQuery('#files_done').attr('disabled', 'disabled');
209           }
210           jQuery('#files_pending').children('span').text('Loading... '+ (upload_pending)+' Remaining')
211   },
212   // Fired when file upload is completed
213   // WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
214   // @param file basename of uploaded file
215   // @param response server response
216   onComplete: function(file, response) {
217 //       console.debug(response);
218          // add file to the list
219          response_array = JSON.parse(response);
220          if (response_array.error==true){
221                  //error, then refresh URL
222 //               console.debug(response_array);
223                  //thumbnail
224                  img = jQuery('<img>').attr('src', '<?php echo $_base_href . AT_PA_BASENAME . "images/no.png" ?>');      
225                  img.attr('alt', '<?php echo _AT("error"); ?>');
226                  img.attr('title', file);
227
228                  //update error log msg
229                  file_msg = jQuery('<div>').text(response_array.msg);
230                  file_msg.attr('style', 'float:left; width: 80%');
231          } else {
232                  //thumbnail
233                  img = jQuery('<img>').attr('src', '<?php echo $_base_href . AT_PA_BASENAME; ?>get_photo.php?aid='+response_array.aid+'&pid='+response_array.pid+'&ph='+response_array.ph);      
234                  img.attr('alt', response_array.alt);
235                  img.attr('title', file);
236                  img.attr('class', 'tn');
237
238                  //update error log msg
239                  file_msg = jQuery('<div>').text('<?php echo _AT("pa_processed"); ?>: ' + file + ' (' + response_array.size );
240                  file_kb = jQuery('<span>').html('<?php echo _AT("kb"); ?>)');
241                  file_kb.appendTo(file_msg);
242                  file_msg.attr('style', 'float:left; width: 80%;');
243          }       
244
245          //image for the x
246          imgx = jQuery('<img>').attr('src', '<?php echo $_base_href . "images/x.gif" ?>');
247          imgx.attr('title', '<?php echo _AT("remove");?> ' + file);
248          imgx.attr('alt', '<?php echo _AT("remove");?> ' + file);
249
250          //deletion link
251          a_delete = jQuery('<a>'); 
252          a_delete.attr('href', '<?php echo $_SERVER["REQUEST_URI"]; ?>#top');
253          //a_delete.attr('onclick', 'deletePhoto('+response_array.aid+', '+response_array.pid+', this);');
254          a_delete.attr('id', response_array.pid);
255          a_delete.click(function(){deletePhoto(response_array.aid, this)});
256           
257          //img wrapper
258          img_wrapper = jQuery('<div>');
259          img_wrapper.attr('style', 'float:left; ');
260          img.appendTo(img_wrapper);
261          a_delete.appendTo(img_wrapper);
262          imgx.appendTo(a_delete);
263
264          //formation
265          li = jQuery('<li></li>');
266          li.prependTo('#ajax_uploader .files');
267          file_msg.appendTo(li);
268          img_wrapper.appendTo(li);
269
270          jQuery('#files_pending').children('span').text('Loading... '+ (--upload_pending)+' Remaining')
271          if (upload_pending == 0){
272                 jQuery('#files_pending').hide();
273                 jQuery('#files_done').removeAttr('disabled');
274           }
275   }
276 });
277
278 //Ajax delete
279 function deletePhoto(aid, thisobj) {
280         var thisobj = thisobj;
281         pid = thisobj.id;
282
283         //run iff it is a photo
284         if(aid > 0 && pid > 0){
285                 xmlhttp=GetXmlHttpObject();
286                 if (xmlhttp==null) {
287                   alert ("Your browser does not support AJAX!");
288                   return;
289                 }
290                 var url='<?php echo $_base_href . AT_PA_BASENAME; ?>remove_uploaded_photo.php?aid='+aid+'&pid='+pid;
291                 xmlhttp.onreadystatechange=function(){
292         //              console.debug(xmlhttp);
293                         if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
294                                 jQuery(thisobj).parent().parent().remove();     //delete from DOM tree.
295                         }
296                 };
297                 xmlhttp.open("GET",url,true);
298                 xmlhttp.send(null);
299         } else {
300                 //simply remove tihs node without running anything in the DB
301                 jQuery(thisobj).parent().parent().remove();     //delete from DOM tree.
302         }
303         if(jQuery('#add_more_photos').length){
304                 jQuery('#add_more_photos').focus();
305         } 
306 }
307
308 function GetXmlHttpObject() {
309         if (window.XMLHttpRequest) {
310           // code for IE7+, Firefox, Chrome, Opera, Safari
311           return new XMLHttpRequest();
312           }
313         if (window.ActiveXObject){
314           // code for IE6, IE5
315           return new ActiveXObject("Microsoft.XMLHTTP");
316           }
317         return null;
318 }
319
320
321 /* 
322  * Toggle add more photo display, and the value of the button
323  */
324 function toggleUploadManager(){
325                 flag = jQuery('#upload_manager_toggle').val();
326                 if (flag==1){
327                         jQuery('#upload_manager').val('<?php echo _AT("pa_close_upload_manager"); ?>');
328                         jQuery('#upload_manager_toggle').val(0);
329                 } else {
330                         jQuery('#upload_manager').val('<?php echo _AT("pa_open_upload_manager"); ?>');
331                         jQuery('#upload_manager_toggle').val(1);
332                 }
333                 jQuery('#ajax_uploader').toggle();              
334 }
335 <?php endif; ?>
336 //]]>
337 </script>