root/modules/branches/2.9/directory/page.directory.php

Revision 11821, 5.4 kB (checked in by mbrevda, 2 years ago)

closes #4973 - better variable validation to defrentiate between blank and null. Thanks michelpy for the report!

Line 
1 <?php
2
3 #Dummy text for localization of Submit button
4 if (false) {
5     _("Submit");
6 }
7
8 //check for ajax request and process that immediately
9 if(isset($_REQUEST['ajaxgettr'])){//got ajax request
10   $opts = $opts=explode('|', urldecode($_REQUEST['ajaxgettr']));
11     if($opts[0] == 'all') {
12     echo directory_draw_entries_all_users($opts[1]);
13     }else{
14         if ($opts[0] != '') {
15             $real_id = $opts[0];
16             $name = '';
17             $realname = $opts[1];
18             $audio = 'vm';
19         } else {
20             $real_id = 'custom';
21             $name = $opts[1];
22             $realname = 'Custom Entry';
23             $audio = 'tts';
24         }
25         echo directory_draw_entries_tr($opts[0], $real_id, $name, $realname, $audio,'',$opts[2]);
26     }
27     exit;
28 }
29
30 //get vars
31 $requestvars = array('id', 'action', 'entries', 'newentries', 'def_dir', 'Submit');
32 foreach ($requestvars as $var){
33     $$var = isset($_REQUEST[$var]) ? $_REQUEST[$var] : '';
34 }
35
36 if (isset($Submit) && $Submit == 'Submit' && isset($def_dir) && $def_dir !== false) {
37     directory_save_default_dir($def_dir);
38 }
39
40 //draw right nav bar
41 directory_drawListMenu();
42
43 ?>
44 <script type="text/javascript">
45 $(document).ready(function() {
46  $('#new_dir').click(function(){
47     window.location.href = 'config.php?type=<?php echo $type ?>&display=directory&action=add';
48     })
49 });
50 </script>
51 <?php
52 if($action == '' && $id == ''){
53     $dirlist = directory_list();
54     array_unshift($dirlist, array('id' => '', 'dirname' => _('none')));
55     $def_dir = directory_get_default_dir();
56     echo '<h2 id="title">Directory</h2>';
57     echo '<br /><br /><input type="button" value="' . _('Add a new Directory') . '" id="new_dir"/>';
58     echo '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post">';
59     echo '<br /><br /><h5>' . _('Directory Options') . '</h5><hr class="dirhr">';
60     echo '<a href="javascript:void(null)" class="info">Default Directory <span style="left: -18px; display: none; ">';
61     echo _('When checked, this becomes the default directory and replaces any other directory as the default directory. This has the effect of exposing entries for this directory into the Extension/User page');
62     echo '</span></a>';
63     echo '&nbsp&nbsp<select name="def_dir">';
64     if (isset($dirlist) && $dirlist) {
65         foreach ($dirlist as $dir) {
66             echo '<option value="' . $dir['id'] . '"';
67             echo  (($dir['id'] == $def_dir) ? ' SELECTED ' : '') . '>';
68             echo $dir['dirname'] ? $dir['dirname'] : _('Directory') . ' ' . $dir['id'];
69             echo '</option>';
70         }
71     }
72     echo '</select>';
73     echo '<br /><br /><input type="submit" name="Submit">';
74     echo '</form><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />';
75 }
76
77 function directory_drawListMenu(){
78     global $id,$type;
79     $results = directory_list();
80     $def_dir = directory_get_default_dir();
81     echo '<div class="rnav"><ul>'."\n";
82     echo "<li><a href=\"config.php?type=$type&display=directory&action=add\">"._('Add Directory')."</a></li>";
83     if($results){
84         foreach ($results as $key=>$result){
85             if (!$result['dirname']) {
86                 $result['dirname'] = 'Directory '.$result['id'];
87             }
88             if ($result['id'] == $def_dir) {
89                 $result['dirname'] = '<span id="defdir" >' . $result['dirname'] . '</span>';
90             }
91             echo "<li><a".($id==$result['id'] ? ' class="current"':''). ' href="config.php?type='.$type.'&display=directory&id='.$result['id'].'">'.$result['dirname']."</a></li>";
92         }
93     }
94     echo "</ul><br /></div>";
95 }
96
97 ?>
98
99 <script type="text/javascript">
100 $(document).ready(function(){
101     //show/hide add button/dropdown
102     $('#addbut').click(function(){
103         $('#addusersel').val('none');//reset select box
104         $(this).fadeOut(250,
105         function(){
106             $('#addrow').fadeIn(250);
107         });
108         return false;
109     });
110    
111     //add row button
112     $('#addrow').change(function(){
113         $(this).fadeOut(250,
114         function(){
115             $('#addbut').not("span").fadeIn(250).find("span").hide();
116         });
117         if($('#addusersel').val() != 'none'){
118             var rownum=$('[class^=entrie]').length+1;
119             //increment id untill we find one that isnt being used
120             while($('.entrie' + rownum).length == 1){
121                 rownum++;
122             }
123             addrow($('#addusersel').val() + '|' + rownum);
124         }
125         return false;
126     });
127    
128     //set toggle value for text-box hint text
129   $(".dpt-title").toggleVal({
130     populateFrom: "title",
131     changedClass: "text-normal",
132     focusClass: "text-normal"
133   });
134     $("form").submit(function() {
135     $(".dpt-title").each(function() {
136       if($(this).val() == $(this).data("defText")) {
137         $(this).val("");
138       }
139     });
140     });
141    
142     //delete row when trash can is clicked
143     $('.trash-tr').live('click', function(){
144     $(this).parents('tr').fadeOut(500,
145         function(){
146             $(this).remove()
147         })
148     });
149    
150    
151 });
152
153
154 //add a new entry to the table
155 function addrow(user){
156     $.ajax({
157         type: 'POST',
158       url: location.href,
159       data: 'ajaxgettr='+encodeURIComponent(user)+'&quietmode=1&skip_astman=1',
160       success: function(data) {
161         $('#dir_entries_tbl > tbody:last').append(data);
162       /* now re-apply toggleval - redundant but they may have appended multipe values so... */
163       $(".dpt-title").not('.text-normal').toggleVal({
164         populateFrom: "title",
165         changedClass: "text-normal",
166         focusClass: "text-normal"
167       });
168       },
169       error: function(XMLHttpRequest, textStatus, errorThrown) {
170       var msg = "<?php echo _("An Error occurred trying to contact the server adding a row, no reply.")?>";
171       alert(msg);
172     }
173   });
174 }
175 </script>
176
177 <style type="text/css">
178 #addrow{display:none;}
179 /*#dir_entries_tbl :not(tfoot) tr:nth-child(odd){background-color:#FCE7CE;}*/
180 .dpt-title {color: #CCCCCC;}
181 .text-normal {color: inherit;}
182 .dirhr{width: 50%; margin-left: 0px;}
183 #defdir{font-weight:bold;}
184 </style>
185
Note: See TracBrowser for help on using the browser.