PageRenderTime 143ms CodeModel.GetById 66ms app.highlight 67ms RepoModel.GetById 1ms app.codeStats 0ms

/htroot/manager/actions/mutate_module.dynamic.php

https://github.com/gunf/novo-isaak.local
PHP | 553 lines | 497 code | 43 blank | 13 comment | 103 complexity | 23f6b58fee1ad788af25de5817fc024a MD5 | raw file
  1<?php
  2if(IN_MANAGER_MODE!='true') die('<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.');
  3
  4switch ((int) $_REQUEST['a']) {
  5    case 107:
  6        if(!$modx->hasPermission('new_module')) {
  7            $e->setError(3);
  8            $e->dumpError();
  9        }
 10        break;
 11    case 108:
 12        if(!$modx->hasPermission('edit_module')) {
 13            $e->setError(3);
 14            $e->dumpError();
 15        }
 16        break;
 17    default:
 18        $e->setError(3);
 19        $e->dumpError();
 20}
 21
 22if (isset($_REQUEST['id']))
 23        $id = (int)$_REQUEST['id'];
 24else    $id = 0;
 25
 26if ($manager_theme)
 27        $manager_theme .= '/';
 28else    $manager_theme  = '';
 29
 30// Get table names (alphabetical)
 31$tbl_active_users       = $modx->getFullTableName('active_users');
 32$tbl_membergroup_names  = $modx->getFullTableName('membergroup_names');
 33$tbl_site_content       = $modx->getFullTableName('site_content');
 34$tbl_site_htmlsnippets  = $modx->getFullTableName('site_htmlsnippets');
 35$tbl_site_module_access = $modx->getFullTableName('site_module_access');
 36$tbl_site_module_depobj = $modx->getFullTableName('site_module_depobj');
 37$tbl_site_modules       = $modx->getFullTableName('site_modules');
 38$tbl_site_plugins       = $modx->getFullTableName('site_plugins');
 39$tbl_site_snippets      = $modx->getFullTableName('site_snippets');
 40$tbl_site_templates     = $modx->getFullTableName('site_templates');
 41$tbl_site_tmplvars      = $modx->getFullTableName('site_tmplvars');
 42
 43// create globally unique identifiers (guid)
 44function createGUID(){
 45    srand((double)microtime()*1000000);
 46    $r = rand() ;
 47    $u = uniqid(getmypid() . $r . (double)microtime()*1000000,1);
 48    $m = md5 ($u);
 49    return $m;
 50}
 51
 52// Check to see the editor isn't locked
 53$sql = 'SELECT internalKey, username FROM '.$tbl_active_users.' WHERE action=108 AND id=\''.$id.'\'';
 54$rs = mysql_query($sql);
 55$limit = mysql_num_rows($rs);
 56if ($limit > 1) {
 57    for ($i = 0; $i < $limit; $i++) {
 58        $lock = mysql_fetch_assoc($rs);
 59        if ($lock['internalKey'] != $modx->getLoginUserID()) {
 60            $msg = sprintf($_lang['lock_msg'], $lock['username'], 'module');
 61            $e->setError(5, $msg);
 62            $e->dumpError();
 63        }
 64    }
 65}
 66// end check for lock
 67
 68// make sure the id's a number
 69if (!is_numeric($id)) {
 70    echo 'Passed ID is NaN!';
 71    exit;
 72}
 73
 74if (isset($_GET['id'])) {
 75    $sql = 'SELECT * FROM '.$tbl_site_modules.' WHERE id=\''.$id.'\'';
 76    $rs = mysql_query($sql);
 77    $limit = mysql_num_rows($rs);
 78    if ($limit > 1) {
 79        echo '<p>Multiple modules sharing same unique id. Not good.<p>';
 80        exit;
 81    }
 82    if ($limit < 1) {
 83        echo '<p>No record found for id: '.$id.'.</p>';
 84        exit;
 85    }
 86    $content = mysql_fetch_assoc($rs);
 87    $_SESSION['itemname'] = $content['name'];
 88    if ($content['locked'] == 1 && $_SESSION['mgrRole'] != 1) {
 89        $e->setError(3);
 90        $e->dumpError();
 91    }
 92} else {
 93    $_SESSION['itemname'] = 'New Module';
 94    $content['wrap'] = '1';
 95}
 96
 97?>
 98<script type="text/javascript">
 99function loadDependencies() {
100    if (documentDirty) {
101        if (!confirm("<?php echo $_lang['confirm_load_depends']?>")) {
102            return;
103        }
104    }
105    documentDirty = false;
106    window.location.href="index.php?id=<?php echo $_REQUEST['id']?>&a=113";
107};
108function duplicaterecord() {
109    if(confirm("<?php echo $_lang['confirm_duplicate_record']?>")==true) {
110        documentDirty=false;
111        document.location.href="index.php?id=<?php echo $_REQUEST['id']?>&a=111";
112    }
113}
114
115function deletedocument() {
116    if(confirm("<?php echo $_lang['confirm_delete_module']?>")==true) {
117        documentDirty=false;
118        document.location.href="index.php?id=" + document.mutate.id.value + "&a=110";
119    }
120}
121
122function setTextWrap(ctrl,b) {
123    if(!ctrl) return;
124    ctrl.wrap = (b)? "soft":"off";
125}
126
127// Current Params
128var currentParams = {};
129
130function showParameters(ctrl) {
131    var c,p,df,cp;
132    var ar,desc,value,key,dt;
133
134    currentParams = {}; // reset;
135
136    if (ctrl) {
137        f = ctrl.form;
138    } else {
139        f= document.forms['mutate'];
140        if(!f) return;
141    }
142
143    // setup parameters
144    tr = (document.getElementById) ? document.getElementById('displayparamrow'):document.all['displayparamrow'];
145    dp = (f.properties.value) ? f.properties.value.split("&"):"";
146    if(!dp) tr.style.display='none';
147    else {
148        t='<table style="margin-bottom:3px;margin-left:14px;background-color:#EEEEEE" cellpadding="2" cellspacing="1"><thead><tr><td><?php echo $_lang['parameter']?></td><td><?php echo $_lang['value']?></td></tr></thead>';
149        for(p = 0; p < dp.length; p++) {
150            dp[p]=(dp[p]+'').replace(/^\s|\s$/,""); // trim
151            ar = dp[p].split("=");
152            key = ar[0];     // param
153            ar = (ar[1]+'').split(";");
154            desc = ar[0];   // description
155            dt = ar[1];     // data type
156            value = decode((ar[2])? ar[2]:'');
157
158            // store values for later retrieval
159            if (key && dt=='list') currentParams[key] = [desc,dt,value,ar[3]];
160            else if (key) currentParams[key] = [desc,dt,value];
161
162            if (dt) {
163                switch(dt) {
164                    case 'int':
165                        c = '<input type="text" name="prop_'+key+'" value="'+value+'" size="30" onchange="setParameter(\''+key+'\',\''+dt+'\',this)" />';
166                        break;
167                    case 'menu':
168                        value = ar[3];
169                        c = '<select name="prop_'+key+'" style="width:168px" onchange="setParameter(\''+key+'\',\''+dt+'\',this)">';
170                        ls = (ar[2]+'').split(",");
171                        if(currentParams[key]==ar[2]) currentParams[key] = ls[0]; // use first list item as default
172                        for(i=0;i<ls.length;i++) {
173                            c += '<option value="'+ls[i]+'"'+((ls[i]==value)? ' selected="selected"':'')+'>'+ls[i]+'</option>';
174                        }
175                        c += '</select>';
176                        break;
177                    case 'list':
178                        value = ar[3];
179                        ls = (ar[2]+'').split(",");
180                        if(currentParams[key]==ar[2]) currentParams[key] = ls[0]; // use first list item as default
181                        c = '<select name="prop_'+key+'" size="'+ls.length+'" style="width:168px" onchange="setParameter(\''+key+'\',\''+dt+'\',this)">';
182                        for(i=0;i<ls.length;i++) {
183                            c += '<option value="'+ls[i]+'"'+((ls[i]==value)? ' selected="selected"':'')+'>'+ls[i]+'</option>';
184                        }
185                        c += '</select>';
186                        break;
187                    case 'list-multi':
188                        value = (ar[3]+'').replace(/^\s|\s$/,"");
189                        arrValue = value.split(",")
190                            ls = (ar[2]+'').split(",");
191                        if(currentParams[key]==ar[2]) currentParams[key] = ls[0]; // use first list item as default
192                        c = '<select name="prop_'+key+'" size="'+ls.length+'" multiple="multiple" style="width:168px" onchange="setParameter(\''+key+'\',\''+dt+'\',this)">';
193                        for(i=0;i<ls.length;i++) {
194                            if(arrValue.length) {
195                                for(j=0;j<arrValue.length;j++) {
196                                    if(ls[i]==arrValue[j]) {
197                                        c += '<option value="'+ls[i]+'" selected="selected">'+ls[i]+'</option>';
198                                    } else {
199                                        c += '<option value="'+ls[i]+'">'+ls[i]+'</option>';
200                                    }
201                                }
202                            } else {
203                                c += '<option value="'+ls[i]+'">'+ls[i]+'</option>';
204                            }
205                        }
206                        c += '</select>';
207                        break;
208                    case 'textarea':
209                        c = '<textarea class="phptextarea" name="prop_'+key+'" cols="50" rows="4" onchange="setParameter(\''+key+'\',\''+dt+'\',this)">'+value+'</textarea>';
210                        break;
211                    default:  // string
212                        c = '<input type="text" name="prop_'+key+'" value="'+value+'" size="30" onchange="setParameter(\''+key+'\',\''+dt+'\',this)" />';
213                        break;
214
215                }
216                t +='<tr><td bgcolor="#FFFFFF">'+desc+'</td><td bgcolor="#FFFFFF">'+c+'</td></tr>';
217            };
218        }
219        t+='</table>';
220        td = (document.getElementById) ? document.getElementById('displayparams'):document.all['displayparams'];
221        td.innerHTML = t;
222        tr.style.display='';
223    }
224    implodeParameters();
225}
226
227function setParameter(key,dt,ctrl) {
228    var v;
229    if(!ctrl) return null;
230    switch (dt) {
231        case 'int':
232            ctrl.value = parseInt(ctrl.value);
233            if(isNaN(ctrl.value)) ctrl.value = 0;
234            v = ctrl.value;
235            break;
236        case 'menu':
237            v = ctrl.options[ctrl.selectedIndex].value;
238            currentParams[key][3] = v;
239            implodeParameters();
240            return;
241            break;
242        case 'list':
243            v = ctrl.options[ctrl.selectedIndex].value;
244            currentParams[key][3] = v;
245            implodeParameters();
246            return;
247            break;
248        case 'list-multi':
249            var arrValues = new Array;
250            for(var i=0; i < ctrl.options.length; i++) {
251                if(ctrl.options[i].selected) {
252                    arrValues.push(ctrl.options[i].value);
253                }
254            }
255            currentParams[key][3] = arrValues.toString();
256            implodeParameters();
257            return;
258            break;
259        default:
260            v = ctrl.value+'';
261            break;
262    }
263    currentParams[key][2] = v;
264    implodeParameters();
265}
266
267// implode parameters
268function implodeParameters() {
269    var v, p, s='';
270    for(p in currentParams) {
271        if(currentParams[p]) {
272            v = currentParams[p].join(";");
273            if(s && v) s+=' ';
274            if(v) s += '&'+p+'='+ v;
275        }
276    }
277    document.forms['mutate'].properties.value = s;
278}
279
280function encode(s) {
281    s=s+'';
282    s = s.replace(/\=/g,'%3D'); // =
283    s = s.replace(/\&/g,'%26'); // &
284    return s;
285}
286
287function decode(s) {
288    s=s+'';
289    s = s.replace(/\%3D/g,'='); // =
290    s = s.replace(/\%26/g,'&'); // &
291    return s;
292}
293
294// Resource browser
295function OpenServerBrowser(url, width, height ) {
296    var iLeft = (screen.width  - width) / 2 ;
297    var iTop  = (screen.height - height) / 2 ;
298
299    var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
300    sOptions += ",width=" + width ;
301    sOptions += ",height=" + height ;
302    sOptions += ",left=" + iLeft ;
303    sOptions += ",top=" + iTop ;
304
305    var oWindow = window.open( url, "FCKBrowseWindow", sOptions ) ;
306}
307
308function BrowseServer() {
309    var w = screen.width * 0.7;
310    var h = screen.height * 0.7;
311    OpenServerBrowser("<?php echo $base_url?>manager/media/browser/mcpuk/browser.html?Type=images&Connector=<?php echo $base_url?>manager/media/browser/mcpuk/connectors/php/connector.php&ServerPath=<?php echo $base_url?>", w, h);
312}
313
314function SetUrl(url, width, height, alt) {
315    document.mutate.icon.value = url;
316}
317</script>
318<script type="text/javascript" src="media/script/tabpane.js"></script>
319<link rel="stylesheet" type="text/css" href="media/style/<?php echo $manager_theme?>style.css?<?php echo $theme_refresher?>" />
320
321<form name="mutate" id="mutate" class="module" method="post" action="index.php?a=109">
322<?php
323    // invoke OnModFormPrerender event
324    $evtOut = $modx->invokeEvent('OnModFormPrerender', array('id' => $id));
325    if(is_array($evtOut)) echo implode('',$evtOut);
326?>
327<input type="hidden" name="id" value="<?php echo $content['id']?>">
328<input type="hidden" name="mode" value="<?php echo $_GET['a']?>">
329
330    <h1><?php echo $_lang['module_title']?></h1>
331
332    <div id="actions">
333          <ul class="actionButtons">
334              <li id="Button1">
335                <a href="#" onclick="documentDirty=false; document.mutate.save.click();">
336                  <img src="<?php echo $_style["icons_save"]?>" /> <?php echo $_lang['save']?>
337                </a>
338                  <span class="and"> + </span>
339                <select id="stay" name="stay">
340                  <?php if ($modx->hasPermission('new_module')) { ?>
341                  <option id="stay1" value="1" <?php echo $_REQUEST['stay']=='1' ? ' selected=""' : ''?> ><?php echo $_lang['stay_new']?></option>
342                  <?php } ?>
343                  <option id="stay2" value="2" <?php echo $_REQUEST['stay']=='2' ? ' selected="selected"' : ''?> ><?php echo $_lang['stay']?></option>
344                  <option id="stay3" value=""  <?php echo $_REQUEST['stay']=='' ? ' selected=""' : ''?>  ><?php echo $_lang['close']?></option>
345                </select>
346              </li>
347              <?php
348                if ($_REQUEST['a'] == '108') { ?>
349              <li id="Button2" class="disabled"><a href="#" onclick="deletedocument();"><img src="<?php echo $_style["icons_delete_document"]?>" /> <?php echo $_lang['delete']?></a></li>
350              <?php } else { ?>
351              <li id="Button2"><a href="#" onclick="deletedocument();"><img src="<?php echo $_style["icons_delete_document"]?>" /> <?php echo $_lang['delete']?></a></li>
352              <?php } ?>
353              <li id="Button5"><a href="#" onclick="documentDirty=false;document.location.href='index.php?a=106';"><img src="<?php echo $_style["icons_cancel"] ?>" /> <?php echo $_lang['cancel']?></a></li>
354              <?php // In Place for future extraction of actionbar
355                    if ($_REQUEST['a'] == '27') { ?>
356                        <li id="Button6"><a href="#" onclick="window.open('<?php echo $modx->makeUrl($id); ?>','previeWin');"><img src="<?php echo $_style["icons_preview"]?>" /> <?php echo $_lang['preview']?></a></li>
357              <?php } ?>
358          </ul>
359    </div>
360    <!-- end #actions -->
361
362<div class="sectionHeader"><?php echo $_lang['module_title']?></div>
363<div class="sectionBody"><p><img class="icon" src="media/style/<?php echo $manager_theme?>images/icons/modules.gif" alt="." width="32" height="32" style="vertical-align:middle;text-align:left;" /> <?php echo $_lang['module_msg']?></p>
364
365<div class="tab-pane" id="modulePane">
366    <script type="text/javascript">
367    tpModule = new WebFXTabPane( document.getElementById( "modulePane"), <?php echo $modx->config['remember_last_tab'] == 1 ? 'true' : 'false'; ?> );
368    </script>
369
370    <!-- General -->
371    <div class="tab-page" id="tabModule">
372    <h2 class="tab"><?php echo $_lang['settings_general']?></h2>
373    <script type="text/javascript">tpModule.addTabPage( document.getElementById( "tabModule" ) );</script>
374
375    <table border="0" cellspacing="0" cellpadding="1">
376        <tr><td align="left"><?php echo $_lang['module_name']?>:</td>
377            <td align="left"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input name="name" type="text" maxlength="100" value="<?php echo htmlspecialchars($content['name'])?>" class="inputBox" style="width:150px;" onchange="documentDirty=true;"><span style="font-family:'Courier New', Courier, mono">&nbsp;</span><span class="warning" id="savingMessage">&nbsp;</span></td></tr>
378        <tr><td align="left"><?php echo $_lang['module_desc']?>:&nbsp;&nbsp;</td>
379            <td align="left"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input name="description" type="text" maxlength="255" value="<?php echo $content['description']?>" class="inputBox" onchange="documentDirty=true;"></td></tr>
380        <tr><td align="left"><?php echo $_lang['icon']?> <span class="comment">(32x32)</span>:&nbsp;&nbsp;</td>
381            <td align="left"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input onchange="documentDirty=true;" type="text" maxlength="255" style="width: 235px;" name="icon" value="<?php echo $content['icon']?>" /> <input type="button" value="<?php echo $_lang['insert']?>" onclick="BrowseServer();" /></td></tr>
382        <tr><td align="left"><?php echo $_lang['existing_category']?>:&nbsp;&nbsp;</td>
383            <td align="left"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span>
384            <select name="categoryid" onchange="documentDirty=true;">
385                <option>&nbsp;</option>
386<?php
387                include_once "categories.inc.php";
388                $ds = getCategories();
389                if ($ds) {
390                    foreach($ds as $n => $v) {
391                        echo "\t\t\t".'<option value="'.$v['id'].'"'.($content['category'] == $v['id'] ? ' selected="selected"' : '').'>'.htmlspecialchars($v['category'])."</option>\n";
392                    }
393                }
394?>
395            </select></td></tr>
396        <tr><td align="left" valign="top" style="padding-top:5px;"><?php echo $_lang['new_category']?>:</td>
397            <td align="left" valign="top" style="padding-top:5px;"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input name="newcategory" type="text" maxlength="45" value="" class="inputBox" onchange="documentDirty=true;"></td></tr>
398        <tr><td align="left"><input name="enable_resource" title="<?php echo $_lang['enable_resource']?>" type="checkbox"<?php echo $content['enable_resource']==1 ? ' checked="checked"' : ''?> class="inputBox" onclick="documentDirty=true;" /> <span style="cursor:pointer" onclick="document.mutate.enable_resource.click();" title="<?php echo $_lang['enable_resource']?>"><?php echo $_lang["element"]?></span>:</td>
399            <td align="left"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input name="sourcefile" type="text" maxlength="255" value="<?php echo $content['sourcefile']?>" class="inputBox" onchange="documentDirty=true;" /></td></tr>
400        <tr><td align="left" valign="top" colspan="2"><input name="disabled" type="checkbox" <?php echo $content['disabled'] == 1 ? 'checked="checked"' : ''?> value="on" class="inputBox" />
401            <span style="cursor:pointer" onclick="document.mutate.disabled.click();"><?php echo  $content['disabled'] == 1 ? '<span class="warning">'.$_lang['module_disabled'].'</span>' : $_lang['module_disabled']?></span></td></tr>
402        <tr><td align="left" valign="top" colspan="2"><input name="locked" type="checkbox"<?php echo $content['locked'] == 1 ? ' checked="checked"' : ''?> class="inputBox" />
403            <span style="cursor:pointer" onclick="document.mutate.locked.click();"><?php echo $_lang['lock_module']?></span> <span class="comment"><?php echo $_lang['lock_module_msg']?></span></td></tr>
404    </table>
405
406    <!-- PHP text editor start -->
407    <div style="width:100%; position:relative">
408        <div style="padding:1px; width:100%; height:16px; background-color:#eeeeee; border-top:1px solid #e0e0e0; margin-top:5px">
409            <span style="float:left; color:#707070; font-weight:bold; padding:3px">&nbsp;<?php echo $_lang['module_code']?></span>
410            <span style="float:right; color:#707070"><?php echo $_lang['wrap_lines']?><input name="wrap" type="checkbox"<?php echo $content['wrap']== 1 ? ' checked="checked"' : ''?> class="inputBox" onclick="setTextWrap(document.mutate.post,this.checked)" /></span>
411        </div>
412        <textarea dir="ltr" class="phptextarea" name="post" style="width:100%; height:370px;" wrap="<?php echo $content['wrap']== 1 ? 'soft' : 'off'?>" onchange="documentDirty=true;"><?php echo htmlspecialchars($content['modulecode'])?></textarea>
413    </div>
414    <!-- PHP text editor end -->
415    </div>
416
417    <!-- Configuration -->
418    <div class="tab-page" id="tabConfig">
419        <h2 class="tab"><?php echo $_lang['settings_config']?></h2>
420        <script type="text/javascript">tpModule.addTabPage( document.getElementById( "tabConfig" ) );</script>
421
422        <table width="90%" border="0" cellspacing="0" cellpadding="0">
423            <tr><td align="left" valign="top"><?php echo $_lang['guid']?>:</td>
424                <td align="left" valign="top"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input name="guid" type="text" maxlength="32" value="<?php echo (int) $_REQUEST['a'] == 107 ? createGUID() : $content['guid']?>" class="inputBox" onchange="documentDirty=true;" /><br /><br /></td></tr>
425            <tr><td align="left" valign="top"><input name="enable_sharedparams" type="checkbox"<?php echo $content['enable_sharedparams']==1 ? ' checked="checked"' : ''?> class="inputBox" onclick="documentDirty=true;" /> <span style="cursor:pointer" onclick="document.mutate.enable_sharedparams.click();"><?php echo $_lang['enable_sharedparams']?>:</span></td>
426                <td align="left" valign="top"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><span ><span class="comment"><?php echo $_lang['enable_sharedparams_msg']?></span></span><br /><br /></td></tr>
427            <tr><td align="left" valign="top"><?php echo $_lang['module_config']?>:</td>
428                <td align="left" valign="top"><span style="font-family:'Courier New', Courier, mono">&nbsp;&nbsp;</span><input name="properties" type="text" maxlength="65535" value="<?php echo $content['properties']?>" class="inputBox phptextarea" style="width:280px;" onchange="showParameters(this);documentDirty=true;" /><input type="button" value="<?php echo $_lang['update_params'] ?>" style="width:16px; margin-left:2px;" title="<?php echo $_lang['update_params']?>" /></td></tr>
429            <tr id="displayparamrow"><td valign="top" align="left">&nbsp;</td>
430                <td align="left" id="displayparams">&nbsp;</td></tr>
431        </table>
432    </div>
433
434<?php if ($_REQUEST['a'] == '108') { ?>
435    <!-- Dependencies -->
436    <div class="tab-page" id="tabDepend">
437    <h2 class="tab"><?php echo $_lang['settings_dependencies']?></h2>
438    <script type="text/javascript">tpModule.addTabPage( document.getElementById( "tabDepend" ) );</script>
439
440    <table width="95%" border="0" cellspacing="0" cellpadding="0">
441    <tr><td align="left" valign="top"><p><?php echo $_lang['module_viewdepend_msg']?><br /><br />
442        <a class="searchtoolbarbtn" href="#" style="float:left" onclick="loadDependencies();return false;"><img src="<?php echo $_style["icons_save"]?>" align="absmiddle" /> <?php echo $_lang['manage_depends']?></a><br /><br /></p></td></tr>
443    <tr><td valign="top" align="left">
444<?php
445    $sql = 'SELECT smd.id, COALESCE(ss.name,st.templatename,sv.name,sc.name,sp.name,sd.pagetitle) AS `name`, '.
446           'CASE smd.type'.
447           ' WHEN 10 THEN \'Chunk\''.
448           ' WHEN 20 THEN \'Document\''.
449           ' WHEN 30 THEN \'Plugin\''.
450           ' WHEN 40 THEN \'Snippet\''.
451           ' WHEN 50 THEN \'Template\''.
452           ' WHEN 60 THEN \'TV\''.
453           'END AS `type` '.
454           'FROM '.$tbl_site_module_depobj.' AS smd '.
455           'LEFT JOIN '.$tbl_site_htmlsnippets.' AS sc ON sc.id = smd.resource AND smd.type = 10 '.
456           'LEFT JOIN '.$tbl_site_content.' AS sd ON sd.id = smd.resource AND smd.type = 20 '.
457           'LEFT JOIN '.$tbl_site_plugins.' AS sp ON sp.id = smd.resource AND smd.type = 30 '.
458           'LEFT JOIN '.$tbl_site_snippets.' AS ss ON ss.id = smd.resource AND smd.type = 40 '.
459           'LEFT JOIN '.$tbl_site_templates.' AS st ON st.id = smd.resource AND smd.type = 50 '.
460           'LEFT JOIN '.$tbl_site_tmplvars.' AS sv ON sv.id = smd.resource AND smd.type = 60 '.
461           'WHERE smd.module=\''.$id.'\' ORDER BY smd.type,name';
462$ds = $modx->dbQuery($sql);
463if (!$ds) {
464    echo "An error occured while loading module dependencies.";
465} else {
466    include_once $base_path."manager/includes/controls/datagrid.class.php";
467    $grd = new DataGrid('', $ds, 0); // set page size to 0 t show all items
468    $grd->noRecordMsg = $_lang['no_records_found'];
469    $grd->cssClass = 'grid';
470    $grd->columnHeaderClass = 'gridHeader';
471    $grd->itemClass = 'gridItem';
472    $grd->altItemClass = 'gridAltItem';
473    $grd->columns = $_lang['element_name']." ,".$_lang['type'];
474    $grd->fields = "name,type";
475    echo $grd->render();
476} ?>
477        </td></tr>
478    </table>
479    </div>
480<?php } ?>
481</div>
482</div>
483
484<?php
485if ($use_udperms == 1) {
486    // fetch user access permissions for the module
487    $groupsarray = array();
488    $sql = 'SELECT * FROM '.$tbl_site_module_access.' WHERE module=\''.$id.'\'';
489    $rs = mysql_query($sql);
490    $limit = mysql_num_rows($rs);
491    for ($i = 0; $i < $limit; $i++) {
492        $currentgroup = mysql_fetch_assoc($rs);
493        $groupsarray[$i] = $currentgroup['usergroup'];
494    }
495
496    if($modx->hasPermission('access_permissions')) { ?>
497<!-- User Group Access Permissions -->
498<div class="sectionHeader"><?php echo $_lang['group_access_permissions']?></div>
499<div class="sectionBody">
500    <script type="text/javascript">
501    function makePublic(b) {
502        var notPublic=false;
503        var f=document.forms['mutate'];
504        var chkpub = f['chkallgroups'];
505        var chks = f['usrgroups[]'];
506        if (!chks && chkpub) {
507            chkpub.checked=true;
508            return false;
509        } else if (!b && chkpub) {
510            if(!chks.length) notPublic=chks.checked;
511            else for(i=0;i<chks.length;i++) if(chks[i].checked) notPublic=true;
512            chkpub.checked=!notPublic;
513        } else {
514            if(!chks.length) chks.checked = (b) ? false : chks.checked;
515            else for(i=0;i<chks.length;i++) if (b) chks[i].checked=false;
516            chkpub.checked=true;
517        }
518    }
519    </script>
520    <p><?php echo $_lang['module_group_access_msg']?></p>
521<?php
522    }
523    $chk = '';
524    $sql = "SELECT name, id FROM ".$tbl_membergroup_names;
525    $rs = mysql_query($sql);
526    $limit = mysql_num_rows($rs);
527    for ($i = 0; $i < $limit; $i++) {
528        $row = mysql_fetch_assoc($rs);
529        $groupsarray = is_numeric($id) && $id > 0 ? $groupsarray : array();
530        $checked = in_array($row['id'], $groupsarray);
531        if($modx->hasPermission('access_permissions')) {
532            if ($checked) $notPublic = true;
533            $chks .= '<input type="checkbox" name="usrgroups[]" value="'.$row['id'].'"'.($checked ? ' checked="checked"' : '').' onclick="makePublic(false)" />'.$row['name']."<br />\n";
534        } else {
535            if ($checked) $chks = '<input type="hidden" name="usrgroups[]"  value="'.$row['id'].'" />' . "\n" . $chks;
536        }
537    }
538    if($modx->hasPermission('access_permissions')) {
539        $chks = '<input type="checkbox" name="chkallgroups"'.(!$notPublic ? ' checked="checked"' : '').' onclick="makePublic(true)" /><span class="warning">'.$_lang['all_usr_groups'].'</span><br />' . "\n" . $chks;
540    }
541    echo $chks;
542?>
543</div>
544<?php } ?>
545
546<input type="submit" name="save" style="display:none;">
547<?php
548// invoke OnModFormRender event
549$evtOut = $modx->invokeEvent('OnModFormRender', array('id' => $id));
550if(is_array($evtOut)) echo implode('',$evtOut);
551?>
552</form>
553<script type="text/javascript">setTimeout('showParameters();',10);</script>