/htroot/manager/actions/mutate_plugin.dynamic.php
PHP | 488 lines | 443 code | 33 blank | 12 comment | 73 complexity | f977a4d9f207826d12b3bf0c5da5f811 MD5 | raw file
- <?php
- if(IN_MANAGER_MODE!="true") die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the MODx Content Manager instead of accessing this file directly.");
- switch((int) $_REQUEST['a']) {
- case 102:
- if(!$modx->hasPermission('edit_plugin')) {
- $e->setError(3);
- $e->dumpError();
- }
- break;
- case 101:
- if(!$modx->hasPermission('new_plugin')) {
- $e->setError(3);
- $e->dumpError();
- }
- break;
- default:
- $e->setError(3);
- $e->dumpError();
- }
- $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
- // check to see the plugin editor isn't locked
- $sql = "SELECT internalKey, username FROM $dbase.`".$table_prefix."active_users` WHERE $dbase.`".$table_prefix."active_users`.action=102 AND $dbase.`".$table_prefix."active_users`.id=$id";
- $rs = mysql_query($sql);
- $limit = mysql_num_rows($rs);
- if($limit>1) {
- for ($i=0;$i<$limit;$i++) {
- $lock = mysql_fetch_assoc($rs);
- if($lock['internalKey']!=$modx->getLoginUserID()) {
- $msg = sprintf($_lang["lock_msg"],$lock['username'],"plugin");
- $e->setError(5, $msg);
- $e->dumpError();
- }
- }
- }
- // end check for lock
- if(isset($_GET['id'])) {
- $sql = "SELECT * FROM $dbase.`".$table_prefix."site_plugins` WHERE $dbase.`".$table_prefix."site_plugins`.id = $id;";
- $rs = mysql_query($sql);
- $limit = mysql_num_rows($rs);
- if($limit>1) {
- echo "Multiple plugins sharing same unique id. Not good.<p>";
- exit;
- }
- if($limit<1) {
- header("Location: /index.php?id=".$site_start);
- }
- $content = mysql_fetch_assoc($rs);
- $_SESSION['itemname']=$content['name'];
- if($content['locked']==1 && $_SESSION['mgrRole']!=1) {
- $e->setError(3);
- $e->dumpError();
- }
- } else {
- $_SESSION['itemname']="New Plugin";
- }
- ?>
- <script language="JavaScript">
- function duplicaterecord(){
- if(confirm("<?php echo $_lang['confirm_duplicate_record'] ?>")==true) {
- documentDirty=false;
- document.location.href="index.php?id=<?php echo $_REQUEST['id']; ?>&a=105";
- }
- }
- function deletedocument() {
- if(confirm("<?php echo $_lang['confirm_delete_plugin']; ?>")==true) {
- documentDirty=false;
- document.location.href="index.php?id=" + document.mutate.id.value + "&a=104";
- }
- }
- function setTextWrap(ctrl,b){
- if(!ctrl) return;
- ctrl.wrap = (b)? "soft":"off";
- }
- // Current Params/Configurations
- var currentParams = {};
- function showParameters(ctrl) {
- var c,p,df,cp;
- var ar,desc,value,key,dt;
- currentParams = {}; // reset;
- if (ctrl) {
- f = ctrl.form;
- } else {
- f= document.forms['mutate'];
- if(!f) return;
- }
- // setup parameters
- tr = (document.getElementById) ? document.getElementById('displayparamrow'):document.all['displayparamrow'];
- dp = (f.properties.value) ? f.properties.value.split("&"):"";
- if(!dp) tr.style.display='none';
- else {
- t='<table width="300" style="margin-bottom:3px;margin-left:14px;background-color:#EEEEEE" cellpadding="2" cellspacing="1"><thead><tr><td width="50%"><?php echo $_lang['parameter']; ?></td><td width="50%"><?php echo $_lang['value']; ?></td></tr></thead>';
- for(p = 0; p < dp.length; p++) {
- dp[p]=(dp[p]+'').replace(/^\s|\s$/,""); // trim
- ar = dp[p].split("=");
- key = ar[0] // param
- ar = (ar[1]+'').split(";");
- desc = ar[0]; // description
- dt = ar[1]; // data type
- value = decode((ar[2])? ar[2]:'');
- // store values for later retrieval
- if (key && (dt=='list' || dt=='list-multi')) currentParams[key] = [desc,dt,value,ar[3]];
- else if (key) currentParams[key] = [desc,dt,value];
- if (dt) {
- switch(dt) {
- case 'int':
- c = '<input type="text" name="prop_'+key+'" value="'+value+'" size="30" onchange="setParameter(\''+key+'\',\''+dt+'\',this)" />';
- break;
- case 'menu':
- value = ar[3];
- c = '<select name="prop_'+key+'" style="width:168px" onchange="setParameter(\''+key+'\',\''+dt+'\',this)">';
- ls = (ar[2]+'').split(",");
- if(currentParams[key]==ar[2]) currentParams[key] = ls[0]; // use first list item as default
- for(i=0;i<ls.length;i++){
- c += '<option value="'+ls[i]+'"'+((ls[i]==value)? ' selected="selected"':'')+'>'+ls[i]+'</option>';
- }
- c += '</select>';
- break;
- case 'list':
- value = ar[3];
- ls = (ar[2]+'').split(",");
- if(currentParams[key]==ar[2]) currentParams[key] = ls[0]; // use first list item as default
- c = '<select name="prop_'+key+'" size="'+ls.length+'" style="width:168px" onchange="setParameter(\''+key+'\',\''+dt+'\',this)">';
- for(i=0;i<ls.length;i++){
- c += '<option value="'+ls[i]+'"'+((ls[i]==value)? ' selected="selected"':'')+'>'+ls[i]+'</option>';
- }
- c += '</select>';
- break;
- case 'list-multi':
- value = typeof ar[3] !== 'undefined' ? (ar[3]+'').replace(/^\s|\s$/,"") : '';
- arrValue = value.split(",");
- ls = (ar[2]+'').split(",");
- if(currentParams[key]==ar[2]) currentParams[key] = ls[0]; // use first list item as default
- c = '<select name="prop_'+key+'" size="'+ls.length+'" multiple="multiple" style="width:168px" onchange="setParameter(\''+key+'\',\''+dt+'\',this)">';
- for(i=0;i<ls.length;i++){
- if(arrValue.length){
- var found = false;
- for(j=0;j<arrValue.length;j++){
- if (ls[i] == arrValue[j]) {
- found = true;
- }
- }
- if(found == true){
- c += '<option value="'+ls[i]+'" selected="selected">'+ls[i]+'</option>';
- }else{
- c += '<option value="'+ls[i]+'">'+ls[i]+'</option>';
- }
- }else{
- c += '<option value="'+ls[i]+'">'+ls[i]+'</option>';
- }
- }
- c += '</select>';
- break;
- case 'textarea':
- c = '<textarea class="phptextarea" name="prop_'+key+'" cols="50" rows="4" onchange="setParameter(\''+key+'\',\''+dt+'\',this)">'+value+'</textarea>';
- break;
- default: // string
- c = '<input type="text" name="prop_'+key+'" value="'+value+'" size="30" onchange="setParameter(\''+key+'\',\''+dt+'\',this)" />';
- break;
- }
- t +='<tr><td bgcolor="#FFFFFF" width="50%">'+desc+'</td><td bgcolor="#FFFFFF" width="50%">'+c+'</td></tr>';
- };
- }
- t+='</table>';
- td = (document.getElementById) ? document.getElementById('displayparams'):document.all['displayparams'];
- td.innerHTML = t;
- tr.style.display='';
- }
- implodeParameters();
- }
- function setParameter(key,dt,ctrl) {
- var v;
- if(!ctrl) return null;
- switch (dt) {
- case 'int':
- ctrl.value = parseInt(ctrl.value);
- if(isNaN(ctrl.value)) ctrl.value = 0;
- v = ctrl.value;
- break;
- case 'menu':
- v = ctrl.options[ctrl.selectedIndex].value;
- currentParams[key][3] = v;
- implodeParameters();
- return;
- break;
- case 'list':
- v = ctrl.options[ctrl.selectedIndex].value;
- currentParams[key][3] = v;
- implodeParameters();
- return;
- break;
- case 'list-multi':
- var arrValues = new Array;
- for(var i=0; i < ctrl.options.length; i++){
- if(ctrl.options[i].selected){
- arrValues.push(ctrl.options[i].value);
- }
- }
- currentParams[key][3] = arrValues.toString();
- implodeParameters();
- return;
- break;
- default:
- v = ctrl.value+'';
- break;
- }
- currentParams[key][2] = v;
- implodeParameters();
- }
- // implode parameters
- function implodeParameters(){
- var v, p, s='';
- for(p in currentParams){
- if(currentParams[p]) {
- v = currentParams[p].join(";");
- if(s && v) s+=' ';
- if(v) s += '&'+p+'='+ v;
- }
- }
- document.forms['mutate'].properties.value = s;
- }
- function encode(s){
- s=s+'';
- s = s.replace(/\=/g,'%3D'); // =
- s = s.replace(/\&/g,'%26'); // &
- return s;
- }