We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21056
    • 327 Posts
    This is an auto-generated support/comment thread for ManagerManager.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    ManagerManager (MM) is a powerful plugin that allows you to change the names, visibility, and layout of document fields within the Manager - and lots more!


    Moderator Note: This resource has now its own dedicated forum here: http://modxcms.com/forums/index.php/board,349.0.html , Please create the new topics for your questions. Thanks smiley
      Author: ManagerManager plugin - customise your ModX manager interface

      Rckt - web development, Sheffield, UK
      • 26104
      • 36 Posts
      Hello,

      Installed you plugin but couldn’t get it working... Added a new role with id 2 and changed the news editors ID into that same ID to test it, but it didn’t work. My plugin config:
      $news = '2';
      	mm_hideField('pagetitle,menutitle,link_attributes,template,menuindex,description,show_in_menu,which_editor,is_folder,is_richtext,log,searchable,cacheable,clear_cache', $news);
      	mm_renameTab('settings', 'Publication settings', $news);
      	mm_synch_fields('pagetitle,menutitle,longtitle', $news);
      	mm_renameField('longtitle','Headline', $news);
      	mm_renameField('alias','Filename (URL)', $news);
      	mm_renameField('parent','Folder', $news);
      	mm_changeFieldHelp('parent', 'To move this story to a different folder: Click this icon to activate, then choose a new folder in the tree on the left.', '', $news_tpl);	
      	


      Any idea?
        • 21056
        • 327 Posts
        Are you logged in as a user assigned that role?

        If you log in as administrator you won’t see it.
          Author: ManagerManager plugin - customise your ModX manager interface

          Rckt - web development, Sheffield, UK
          • 21056
          • 327 Posts
          New version (0.2.3) released -- main improvement is that now you can get a list of roles and template IDs when you are editing the ruleset.
            Author: ManagerManager plugin - customise your ModX manager interface

            Rckt - web development, Sheffield, UK
            • 7923
            • 4,213 Posts
            Wow, didn’t see this plugin added until now.. Sounds very nice, thanks alot for your contribution!


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 21056
              • 327 Posts
              Thanks! Here’s a couple of screenshots to show what it can do.

              (This is using our customised manager theme, hence the red)
                Author: ManagerManager plugin - customise your ModX manager interface

                Rckt - web development, Sheffield, UK
                • 19164
                • 1,215 Posts
                1. Typo in 0.2.4. plugin.txt - 34 / /For everyone except administrators

                2. Im install clear modx site, install plugin and get error

                unterminated string literal 
                $('div#'+mm_lastTab).after('\n


                Code near this point
                <script src="http://code.jquery.com/jquery-latest.pack.js" type="text/javascript" charset="utf-8"></script><script type="text/javascript">
                471mm_lastTab = 'tabEvents';
                472 // ----------- Create tab --------------
                $('div#'+mm_lastTab).after('
                474<div class="tab-page" id="tabrolestemplates">
                475<h2 class="tab">Roles & Templates</h2>



                UPD I found, that
                // Clean up for js output
                $empty_tab = str_replace("\n", '', $empty_tab);
                $empty_tab = str_replace("\t", '', $empty_tab);

                in mm.inc.php is someone not working for me...
                  DirectResize 0.9 beta. PHPThumb, sets of configurations, configuration, binded to specific path. No backward compatibility. | DirectResize 0.9. PHPThumb, наборы параметров, параметры, привязанные к определенным путям. Без обратной совместимости.

                  Unfortunately, DirectResize project is closed. If you want to continue development, PM me for access to project page on Google Code. К сожалению, проект DirectResize закрыт. Если вы желаете продолжить разработки, обращайтесь через ПМ для получения доступа к репозиторию на Google Code.

                  [PLUGIN] DirectResize - as Maxigallery but for single images :: Download :: [url=http://modxcms.com/forums/index.php/topic,21490]
                  • 24292
                  • 28 Posts
                  This doesn’t seem to work, even in a fresh install of MODx 0.96 because of conflicts with mootools.
                  Below is my modified version of mm.inc.php which uses var $j = jQuery.noConflict(); and $j(...) rather than $(...) throughout.
                  Seems to be working but I would welcome ncrossland checking the changes.

                  Also, mm_hideField in the example plugin.txt should be mm_hideFields

                  <?php
                  /*
                      @name       ManagerManager
                      @version    0.2.4, 2007-08-02
                      
                      @for        MODx 0.9.6
                      
                      @author     Nick Crossland - www.rckt.co.uk
                      @modified Rachael Black: to use var $j = jQuery.noConflict(); throughout
                  
                      @DESCRIPTION
                      Used to manipulate the display of document fields in the manager.
                      
                      @INSTALLATION:
                      1. Download jquery.js from http://jquery.com/src/jquery-latest.pack.js
                      2. Put it in /assets/js/
                  	3. In ModX manager, create a new plugin and paste in the code from plugin.txt
                  	4. In the "system events" tab, check the OnDocFormRender and OnDocFormPrerender checkboxes
                  	5. Put this file in /assets/plugins/managermanager (if you want to put it somewhere else, you'll need to change the path in the plugin text you pasted in step 3) 
                      6. Insert your rules into the marked section within the plugin code in the manager
                      
                      @INSPIRATION:
                      HideEditor plugin by Timon Reinhard and Gildas; HideManagerFields by Brett @ The Man Can!
                  	
                  	@LICENSE:
                  	(c) Rocket Science Solutions Ltd - www.rckt.co.uk	
                  	Released under the GNU General Public License: http://creativecommons.org/licenses/GPL/2.0/
                  	
                  */
                  
                  // Set variables
                  global $content,$default_template, $mm_current_page, $mm_fields;
                  $mm_current_page = array();
                  $mm_current_page['template'] = isset($content['template']) ? $content['template'] : $default_template;
                  $mm_current_page['role'] = $_SESSION['mgrRole'];
                  
                  // Default value
                  $js_url = ($js_url=='') ? 'http://code.jquery.com/jquery-latest.pack.js' : $js_url;
                  
                  // What are the fields we can change, and what types are they?
                  $mm_fields = array(
                  	'pagetitle' => array('fieldtype'=>'input', 'fieldname'=>'pagetitle'),
                  	'longtitle' => array('fieldtype'=>'input', 'fieldname'=>'longtitle'),
                  	'description' => array('fieldtype'=>'input', 'fieldname'=>'description'),
                  	'alias' => array('fieldtype'=>'input', 'fieldname'=>'alias'),
                  	'link_attributes' => array('fieldtype'=>'input', 'fieldname'=>'link_attributes'),
                  	'introtext' => array('fieldtype'=>'textarea', 'fieldname'=>'introtext'), 
                  	'template' => array('fieldtype'=>'select', 'fieldname'=>'template'),  
                  	'menutitle' => array('fieldtype'=>'input', 'fieldname'=>'menutitle'),
                  	'menuindex' => array('fieldtype'=>'input', 'fieldname'=>'menuindex'),
                  	'show_in_menu' => array('fieldtype'=>'input', 'fieldname'=>'hidemenucheck'),
                  	'parent' => array('fieldtype'=>'input', 'fieldname'=>'parent'),
                  	'is_folder' => array('fieldtype'=>'input', 'fieldname'=>'isfoldercheck'),
                  	'is_richtext' => array('fieldtype'=>'input', 'fieldname'=>'richtextcheck'),
                  	'log' => array('fieldtype'=>'input', 'fieldname'=>'donthitcheck'),
                  	'published' => array('fieldtype'=>'input', 'fieldname'=>'publishedcheck'),
                  	'pub_date' => array('fieldtype'=>'input', 'fieldname'=>'pub_date'),
                  	'unpub_date' => array('fieldtype'=>'input', 'fieldname'=>'unpub_date'),
                  	'searchable' => array('fieldtype'=>'input', 'fieldname'=>'searchablecheck'),
                  	'cacheable' => array('fieldtype'=>'input', 'fieldname'=>'cacheablecheck'),
                  	'clear_cache' => array('fieldtype'=>'input', 'fieldname'=>'syncsitecheck'),
                  	'content_type' => array('fieldtype'=>'select', 'fieldname'=>'contentType'),
                  	'content_dispo' => array('fieldtype'=>'select', 'fieldname'=>'content_dispo'),
                  	'keywords' => array('fieldtype'=>'select', 'fieldname'=>'keywords[]'),
                  	'metatags' => array('fieldtype'=>'select', 'fieldname'=>'metatags[]'),
                  	'content' => array('fieldtype'=>'textarea', 'fieldname'=>'content'),
                  	'which_editor' => array('fieldtype'=>'select', 'fieldname'=>'which_editor')
                  );				
                  
                  
                    // if this is being included for the second time, we don't want to redeclare all these functions. Let's just test for one of them
                    // and if it is already defined, stop processing this file any further.
                  if (!function_exists("mm_default")) {
                  
                  
                    // Sets a default value for a field when creating a new document
                  function mm_default($field, $value='', $roles='', $templates='', $eval=false) {
                  	global $mm_fields, $modx;
                  	$e = &$modx->Event;
                  
                  	  // if we aren't creating a new document or folder, we don't want to do this
                  	if (!($modx->manager->action == "85" || $modx->manager->action == "4")) {
                  		return;
                  	} 
                  
                  	// What's the new value, and does it include PHP?
                  	$new_value = ($eval) ? eval($value) : $value;
                  
                  	$output = " // ----------- Date defaults -------------- \n";
                  
                  	switch ($field) {
                  		case 'pub_date':
                  			$new_value = ($new_value=='') ? date("d-m-Y H:i:s") : $new_value;
                  			$output .= '$j("input[@name=pub_date]").val("'.htmlentities($new_value).'"); '."\n";
                  		break;
                  		
                  		case 'unpub_date':
                  			$new_value = ($new_value=='') ? date("d-m-Y H:i:s") : $new_value;
                  			$output .= '$j("input[@name=unpub_date]").val("'.htmlentities($new_value).'"); '."\n";
                  		break;
                  		
                  		default:
                  			return;
                  		break;
                  	}	
                  	$e->output($output . "\n");	
                  }
                  
                  
                  
                  
                  // Inherit values from a parent
                  function mm_inherit($fields, $roles='', $templates='') {
                  
                  	global $mm_fields, $modx;
                  	$e = &$modx->Event;
                  	
                  	// if we've been supplied with a string, convert it into an array 
                  	if (!is_array($fields)) {
                  		$fields = makeArray($fields);
                  	}
                  	
                  	// if we aren't creating a new document or folder, we don't want to do this
                  	if (!($modx->manager->action == "85" || $modx->manager->action == "4")) {
                  		return;
                  	} 
                  	
                  	// Are we using thie rule?
                  	if (useThisRule($roles, $templates)) {
                  	
                  		$output = " // ----------- Inherit -------------- \n";
                  	
                  		// Get the parent info
                  		if (isset($_REQUEST['pid'])){
                  			$parentID = $modx->getPageInfo($_REQUEST['pid'],0,'id');
                  			$parentID = $parentID['id'];
                  		} else {
                  			$parentID = 0;
                  		}
                  		
                  		foreach ($fields as $field) { 
                  			switch ($field) {
                  						
                  				default:
                  				
                  					// get some info about the field we are being asked to use
                  					if (isset($mm_fields[$field])) {
                  						$fieldtype = $mm_fields[$field]['fieldtype'];
                  						$fieldname = $mm_fields[$field]['fieldname'];
                  					} else {
                  						break;
                  					}
                  				
                  					// Get this field data from the parent
                  					$newArray = $modx->getDocument($parentID, $fieldname);
                  					$newvalue = $newArray[$fieldname];
                  					
                  					if ($fieldtype == 'input') {
                  						$output .=  '$j("input[@name='.$fieldname.']").val("' . htmlentities($newvalue) . '"); ';
                  					}
                  					
                  				break;	
                  			}	
                  			$e->output($output . "\n");
                  		}		
                  	}
                  }
                  
                  
                  
                  
                  
                  
                  
                  // Change the label for an element
                  function mm_renameField($field, $newlabel, $roles='', $templates='', $newhelp='') {
                  
                  	global $mm_fields, $modx;
                  	$e = &$modx->Event;
                  		
                  	// if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
                  	if (useThisRule($roles, $templates)) {
                  	
                  	$output = " // ----------- Rename field -------------- \n";
                  		
                  			switch ($field) {
                  			
                  				// Exceptions
                  				case 'keywords':
                  					$output .= '$j("select[@name*=keywords]").siblings("span.warning").empty().prepend("'.htmlentities($newlabel).'");';
                  				break;
                  				
                  				case 'metatags':
                  					$output .= '$j("select[@name*=metatags]").siblings("span.warning").empty().prepend("'.htmlentities($newlabel).'");';
                  				break;
                  						
                  				case 'hidemenu':
                  					$output .= '$j("input[@name=hidemenucheck]").siblings("span.warning").empty().prepend("'.htmlentities($newlabel).'");';
                  				break;
                  				
                  				case 'which_editor':
                  					$output .= '$j("#which_editor").prev("span.warning").empty().prepend("'.htmlentities($newlabel).'");';
                  				break;
                  				
                  				// We can't rename content box
                  				case 'content':
                  					$output .='';
                  				break;
                  			
                  				// Ones that follow the regular pattern
                  				default:
                  				
                  				// What type is this field?
                  				if (isset($mm_fields[$field])) {
                  					$fieldtype = $mm_fields[$field]['fieldtype'];
                  					$fieldname = $mm_fields[$field]['fieldname'];
                  				} else {
                  					break;
                  				}
                  				
                  				$output .= '$j("'.$fieldtype.'[@name='.$fieldname.']").parents("td").prev("td").children("span.warning").empty().prepend("'.htmlentities($newlabel).'");';
                  				
                  				break;
                  			}	// end switch
                  			
                  
                  			$e->output($output . "\n");
                  			
                  			// If new help has been supplied, do that too
                  			if ($newhelp != '') {
                  				mm_changeFieldHelp($field, $newhelp, $roles, $templates);
                  			}
                  			
                  	} // end if
                  } // end function
                  
                  
                  
                  
                  
                  
                  
                  // Hide a field
                  function mm_hideFields($fields, $roles='', $templates='') {
                  
                  	global $mm_fields, $modx;
                  	$e = &$modx->Event;	
                  		
                  	// if we've been supplied with a string, convert it into an array 
                  	if (!is_array($fields)) {
                  		$fields = makeArray($fields);
                  	}
                  		
                  	// if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
                  	if (useThisRule($roles, $templates)) {
                  	
                  	$e->output(" // ----------- Hide fields -------------- \n");
                  	
                  		foreach ($fields as $field) {
                  		
                  			$output = '';
                  			
                  			switch ($field) {	
                  			
                  				// Exceptions
                  				case 'keywords':
                  					$output .= '$j("select[@name*=keywords]").parent("td").hide();';
                  				break;
                  				
                  				case 'metatags':
                  					$output .= '$j("select[@name*=metatags]").parent("td").hide()';
                  				break;
                  						
                  				case 'hidemenu':
                  					$output .= '$j("input[@name=hidemenucheck]").parent("td").hide();';
                  				break;
                  						
                  				case 'menuindex':
                  					$output .= '$j("input[@name=menuindex]").parents("table").parent("td").prev("td").children("span.warning").hide();' ."\n";
                  					$output .= '$j("input[@name=menuindex]").parent("td").hide();';
                  				break;
                  				
                  				case 'which_editor':
                  					$output .= '$j("select#which_editor").prev("span.warning").hide();' . "\n";
                  					$output .= '$j("select#which_editor").hide();';
                  				break;
                  				
                  				case 'content':
                  					$output .= '$j("#ta").parents("div").parents("div.sectionBody").hide().prev("div.sectionHeader").hide();';
                  				break;
                  				
                  				case 'pub_date':
                  					$output .= '$j("input[@name=pub_date]").parents("tr").next("tr").hide(); '."\n";
                  					$output .= '$j("input[@name=pub_date]").parents("tr").hide(); ';
                  				break;
                  				
                  				case 'unpub_date':
                  					$output .= '$j("input[@name=unpub_date]").parents("tr").next("tr").hide(); '."\n";
                  					$output .= '$j("input[@name=unpub_date]").parents("tr").hide(); ';
                  				break;
                  			
                  				// Ones that follow the regular pattern
                  				default:
                  				
                  					// What type is this field?
                  					if (isset($mm_fields[$field])) {
                  						$fieldtype = $mm_fields[$field]['fieldtype'];
                  						$fieldname = $mm_fields[$field]['fieldname'];
                  					} else {
                  						break;
                  					}
                  					
                  					$output .= '$j("'.$fieldtype.'[@name='.$fieldname.']").parents("tr").hide(); ';
                  				
                  				break;
                  			} // end switch
                  			$e->output($output . "\n");
                  		} // end foreach	
                  	} // end if
                  } // end function
                  
                  
                  
                  
                  
                  // Change the help text of a field
                  function mm_changeFieldHelp($field, $helptext='', $roles='', $templates='') {
                  
                  	global $mm_fields, $modx;
                  	$e = &$modx->Event;	
                  		
                  	if ($helptext=='') {
                  		return;
                  	}
                  	
                  	// if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
                  	if (useThisRule($roles, $templates)) {
                  	
                  	$output = " // ----------- Change field help -------------- \n";
                  	
                  			switch ($field) {
                  			
                  				// Exceptions
                  				case 'parent':
                  					$output .= '$j("input[@name=parent]").siblings("span.comment").empty().prepend("'.htmlentities($helptext).'"); ';
                  				break;
                  				
                  				// Ones that follow the regular pattern
                  				default:
                  				
                  				// What type is this field?
                  				if (isset($mm_fields[$field])) {
                  					$fieldtype = $mm_fields[$field]['fieldtype'];
                  					$fieldname = $mm_fields[$field]['fieldname'];
                  				} else {
                  					break;
                  				}
                  				
                  				$output .= '$j("'.$fieldtype.'[@name='.$fieldname.']").siblings("img[@style:contains(\'cursor:help\')]").attr("alt", "'.htmlentities($helptext).'"); ';
                  				
                  				break;
                  			} // end switch
                  			$e->output($output . "\n");
                  	} // end if
                  } // end function
                  
                  
                  
                  
                  
                  // Rename a tab
                  function mm_renameTab($tab, $newname, $roles='', $templates='') {
                  
                  	global $modx;
                  	$e = &$modx->Event;
                  			
                  	// if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
                  	if (useThisRule($roles, $templates)) {
                  	
                  	$output = " // ----------- Rename tab -------------- \n";
                  		
                  			switch ($tab) {
                  			
                  				case 'general': 
                  					$output .= '$j("div#documentPane h2:nth-child(1) span").empty().prepend("'.htmlentities($newname).'");' . "\n";
                  				break;
                  				
                  				case 'settings': 
                  					$output .= '$j("div#documentPane h2:nth-child(2) span").empty().prepend("'.htmlentities($newname).'");' . "\n";
                  				break;
                  				
                  				case 'meta': 
                  					$output .= '$j("div#documentPane h2:nth-child(3) span").empty().prepend("'.htmlentities($newname).'");' . "\n";
                  				break;
                  				
                  				case 'preview': 
                  					$output .= '$j("div#documentPane h2:nth-child(4) span").empty().prepend("'.htmlentities($newname).'");' . "\n";
                  				break;
                  			} // end switch
                  			$e->output($output . "\n");
                  	}	// end if
                  } // end function
                  
                  
                  
                  
                  
                  // Hide a tab
                  function mm_hideTabs($tabs, $roles='', $templates='') {
                  
                  	global $modx;
                  	$e = &$modx->Event;
                  	
                  	// if we've been supplied with a string, convert it into an array 
                  	if (!is_array($tabs)) {
                  		$tabs = makeArray($tabs);
                  	}
                  			
                  	// if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
                  	if (useThisRule($roles, $templates)) {
                  	
                  	$output = " // ----------- Hide tabs -------------- \n";
                  	
                  		foreach($tabs as $tab) {
                  	
                  			switch ($tab) {
                  			
                  				case 'general': 
                  					$output .= 'if (tpSettings.getSelectedIndex() == 0) { tpSettings.setSelectedIndex(1); } ' . "\n";
                  					$output .= '$j("div#documentPane h2:nth-child(1)").hide(); ' . "\n";
                  					$output .= '$j("#tabMeta").hide(); ';
                  					$output .= '$j("#tabGeneral").hide();';
                  				break;
                  				
                  				case 'settings': 
                  					$output .= 'if (tpSettings.getSelectedIndex() == 1) { tpSettings.setSelectedIndex(0); } ' . "\n";
                  					$output .= '$j("div#documentPane h2:nth-child(2)").hide(); ' . "\n";
                  					$output .= '$j("#tabMeta").hide(); ';
                  					$output .= '$j("#tabSettings").hide();';
                  				break;
                  				
                  				case 'meta': 
                  					$output .= 'if (tpSettings.getSelectedIndex() == 2) { tpSettings.setSelectedIndex(0); } ' . "\n";
                  					$output .= '$j("div#documentPane h2:nth-child(3)").hide(); ' . "\n";
                  					$output .= '$j("#tabMeta").hide(); ';
                  				break;
                  				
                  				case 'preview': 
                  					$output .= 'if (tpSettings.getSelectedIndex() == 3) { tpSettings.setSelectedIndex(0); } ' . "\n";
                  					$output .= '$j("div#documentPane h2:nth-child(4)").hide(); ' . "\n";
                  					$output .= '$j("#tabPreview").hide();';
                  				break;
                  			} // end switch
                  			$e->output($output . "\n");
                  		} // end foreach
                  	}	// end if
                  } // end function
                  
                  
                  
                  
                    // Create a new tab
                  function mm_createTab($name, $id, $roles='', $templates='', $intro='', $width='450') {
                  
                  	global $modx;
                  	$e = &$modx->Event;
                  		
                  	// if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
                  	if (useThisRule($roles, $templates)) {
                  		  // Plugin page tabs use a differen name for the tab object
                  		$js_tab_object = ($e->name == 'OnPluginFormRender') ? 'tpSnippet' : 'tpSettings';
                  	
                  	$output = " // ----------- Create tab -------------- \n";
                  
                  		$empty_tab = '		
                  <div class="tab-page" id="tab'.$id.'">
                  	<h2 class="tab">'.$name.'</h2>
                  	<div class="tabIntro" id="tab-intro-'.$id.'">'.$intro.'</div>
                  	<table width="'.$width.'" border="0" cellspacing="0" cellpadding="0" id="table-'.$id.'">
                  	</table>
                  </div>
                  		';
                  			
                  		// Clean up for js output
                  		$empty_tab = str_replace("\n", '', $empty_tab);
                  		$empty_tab = str_replace("\t", '', $empty_tab);
                  		
                  		$output .= "\$j('div#'+mm_lastTab).after('".$empty_tab."'); \n";
                  		$output .= "mm_lastTab = 'tab".$id."'; \n";
                  		$output .= $js_tab_object. '.addTabPage( document.getElementById( "tab'.$id.'" ) ); ';
                  		
                  		$e->output($output . "\n");	
                  	}	// end if
                  } // end function
                  
                  
                  
                  
                  // Move a field to a different tab
                  function mm_moveFieldsToTab($fields, $newtab, $roles='', $templates='') {
                  
                  	global $modx, $mm_fields;
                  	$e = &$modx->Event;
                  	
                  	// if we've been supplied with a string, convert it into an array 
                  	if (!is_array($fields)) {
                  		$fields = makeArray($fields);
                  	}
                  			
                  	// if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
                  	if (useThisRule($roles, $templates)) {
                  	
                  	$output = " // ----------- Move field to tab -------------- \n";
                  	
                  		// If it's one of the default tabs, we need to get the capitalisation right
                  		switch ($newtab) {
                  			case 'general':
                  			case 'settings':
                  			case 'meta':
                  			case 'preview':
                  				$newtab = ucfirst($newtab);
                  			break;
                  		}
                  		
                  		// Make sure the new tab exists in the DOM
                  		$output .= "if (\$j('#tab".$newtab."').length > 0) { \n";
                  			
                  		// Go through each field that has been supplied
                  		foreach ($fields as $field) {
                  
                  			switch ($field) {
                  			
                  				// We can't move these fields because they belong in a particular place
                  				case 'keywords':
                  				case 'metatags':
                  				case 'which_editor':
                  				case 'content':
                  				case 'hidemenu':
                  				case 'menuindex':
                  				break;
                  				
                  				case 'pub_date':
                  					$output .= 'var helpline = $j("input[@name=pub_date]").parents("tr").next("tr").remove().clone().appendTo("#tab'.$newtab.'>table:first"); ' . "\n";
                  					$output .= '$j(helpline).before($j("input[@name=pub_date]").parents("tr").remove().clone()); ' . "\n";
                  					break;
                  
                  				case 'unpub_date':
                  					$output .= 'var helpline = $j("input[@name=unpub_date]").parents("tr").next("tr").remove().clone().appendTo("#tab'.$newtab.'>table:first"); ' . "\n";
                  					$output .= '$j(helpline).before($j("input[@name=unpub_date]").parents("tr").remove().clone()); ' . "\n";
                  					break;
                  			
                  				
                  				default:
                  				
                  					// What type is this field?
                  					if (isset($mm_fields[$field])) {
                  						$fieldtype = $mm_fields[$field]['fieldtype'];
                  						$fieldname = $mm_fields[$field]['fieldname'];
                  						$output .= '$j("'.$fieldtype.'[@name='.$fieldname.']").parents("tr").remove().clone().appendTo("#tab'.$newtab.'>table:first"); ' . "\n";
                  					} else {	// If we don't know about it, it is most likely a template variable, expecially if it begins with tv
                  						if (substr($field, 0, 2) == 'tv') {
                  							$output .= 'var tv = $j("[@name^='.$field.']:first").parents("tr"); ' . "\n";
                  							$output .= '$j(tv).next("tr").remove(); ' . "\n";
                  							$output .= 'var newTV = $j(tv).remove().clone().appendTo("#tab'.$newtab.'>table:first"); ' . "\n";
                  							$output .= '$j(newTV).after(\'<tr style="height: 10px"><td colspan="2"><div class="split"></div></td></tr>\'); ';
                  						} else {	// if it's not a template variable, don't deal with it
                  							break;
                  						}
                  					}	
                  								
                  						
                  				break;
                  			
                  			} // end switch	
                  		} // end foreach
                  		
                  		$output .= "}";
                  		$e->output($output . "\n");
                  		
                  	}	// end if
                  } // end function
                  
                  
                  
                  
                  
                  // Synch two fields in real time
                  function mm_synch_fields($fields, $roles='', $templates='') {
                  
                  	global $modx, $mm_fields;
                  	$e = &$modx->Event;
                  	
                  		// if we've been supplied with a string, convert it into an array 
                  	if (!is_array($fields)) {
                  		$fields = makeArray($fields);
                  	}
                  	
                  	// We need at least 2 values
                  	if (count($fields)<2) {
                  		return;
                  	}
                  		
                  	// if the current page is being edited by someone in the list of roles, and uses a template in the list of templates
                  	if (useThisRule($roles, $templates)) {
                  	
                  	$output = " // ----------- Synch fields -------------- \n";
                  	
                  			$output .= '
                  				synch_field[mm_sync_field_count] = new Array();
                  			';
                  	
                  		foreach ($fields as $field) {
                  		
                  			// If one of the fields is a TV
                  			if (substr($field, 0, 2) == 'tv') {
                  			
                  				$output .= '
                  					synch_field[mm_sync_field_count].push($j("#'.$field.'"));
                  				';
                  			
                  			// If a propoer field, what type are the fields?
                  			} else if (isset($mm_fields[$field])) { 	
                  				$fieldtype = $mm_fields[$field]['fieldtype'];
                  				$fieldname = $mm_fields[$field]['fieldname'];
                  				// Make sure we're dealing with an input
                  				if ($fieldtype != 'input') {
                  					break;
                  				}
                  				
                  				// Add this field to the array of fields being synched
                  				$output .= '
                  					synch_field[mm_sync_field_count].push($j("'.$fieldtype.'[@name='.$fieldname.']"));
                  				';
                  			
                  			// Or we don't recognise it
                  			} else {break;}	
                  
                  			
                  
                  		} // end foreach
                  		
                  		// Output some javascript to sync these fields
                  		$output .= '
                  			$.each(synch_field[mm_sync_field_count], function(i,n) {
                  				$.each(synch_field[mm_sync_field_count], function(j,m) {
                  					if (i!=j) {
                  						n.change( function() { m.val(this.value); } );
                  					}
                  				});
                  			});
                  			
                  			mm_sync_field_count++;
                  		';
                  		
                  		$e->output($output . "\n");
                  		
                  	}	// end if
                  }
                  
                  
                  
                  // Pass useThisRule a comma separated list of allowed roles and templates, and it will
                  // return TRUE or FALSE to indicate whether this rule should be run on this page
                  function useThisRule($roles='', $templates='') {
                  
                  //$e->output('Roles supplied: '.print_r($roles, true)."\n");
                  	//	$e->output('Current role: '.$mm_current_page['role']."\n");
                  	//	$e->output('Templates supplied: '.print_r($templates, true)."\n");
                  	//	$e->output('Current templates: '.$mm_current_page['template']."\n");
                  
                  	global $mm_current_page, $modx;
                  	$e = &$modx->Event;
                  	
                  	$exclude_roles = false;
                  	$exclude_templates = false;
                  	
                  	// Are they negative roles?
                  	if (substr($roles, 0, 1) == '!') {
                  		$roles = substr($roles, 1);
                  		$exclude_roles = true;
                  	}
                  	
                  	// Are they negative templates?
                  	if (substr($templates, 0, 1) == '!') {
                  		$templates = substr($templates, 1);
                  		$exclude_templates = true;
                  	}
                  	
                  	// Make the lists into arrays
                  	$roles = makeArray($roles);
                  	$templates = makeArray($templates);
                  	
                  	// Does the current role match the conditions supplied?
                  	$match_role_list = ($exclude_roles) ? !in_array($mm_current_page['role'], $roles) : in_array($mm_current_page['role'], $roles);
                  
                  	// Does the current template match the conditions supplied?
                  	$match_template_list = ($exclude_templates) ? !in_array($mm_current_page['template'], $templates) : in_array($mm_current_page['template'], $templates);
                  	
                  	// If we've matched either list in any way, return true	
                  	if ( ($match_role_list || count($roles)==0) && ($match_template_list || count($templates)==0) ) {
                  		return true;
                  	} 
                  	
                  	return false;
                  }
                  
                  
                  
                  // makes a commas separated list into an array
                  function makeArray($csv) {
                  	if (trim($csv)=='') {
                  		return array();
                  	}
                  	$return = explode(',',$csv);
                  	array_walk( $return, create_function('$v, $k', 'return trim($v);'));	// Remove any whitespace
                  	return $return;
                  }
                  
                  
                  } // end function_exists("mm_default")
                  
                  // Check the current event
                  global $e;
                  $e = &$modx->Event;
                  
                  
                  // Do something for each event
                  if ($e->name == 'OnDocFormPrerender') {
                  
                  	// Load the jquery library
                  	echo '<script src="'.$js_url.'" type="text/javascript" charset="utf-8"></script>';
                  
                  	  // Create a mask to cover the page while the fields are being rearranged
                  	echo '<script> var $j = jQuery.noConflict();		
                  		<div id="loadingmask"> </div>
                  		<script type="text/javascript">
                  			$j("#loadingmask").css( {width: "100%", height: $j("body").height(), position: "absolute", zIndex: "1000", backgroundColor: "#ffffff"} );
                  		</script>	
                  	';
                  
                  } else if ($e->name == 'OnPluginFormRender') {	// if it's the plugin config form, give us a copy of all the relevant values
                  	  // if it's the right plugin
                  	if (strtolower($e->activePlugin) == 'managermanager') {	
                  		  // Get all templates
                  		$result = $modx->db->select("templatename, id, description", $modx->db->config['table_prefix']."site_templates", '', 'templatename ASC');
                  		$all_templates = $modx->db->makeArray( $result );
                  		$template_table = '<table>';
                  		$template_table .= '<tr><th class="gridHeader">Template name</th><th class="gridHeader">Template description</th><th class="gridHeader">ID</th></tr>';
                  		$template_table .= '<tr><td class="gridItem">(blank)</td><td class="gridItem">Blank</td><td class="gridItem">0</td></tr>';
                  		foreach ($all_templates as $count=>$tpl) {
                  			$class = ($count % 2) ? 'gridItem':'gridAltItem';
                  			$template_table .= '<tr>';
                  			$template_table .= '<td class="'.$class.'">'.$tpl['templatename'].'</td>';
                  			$template_table .= '<td class="'.$class.'">'.$tpl['description'].'</td>';
                  			$template_table .= '<td class="'.$class.'">'.$tpl['id'].'</td>';
                  			$template_table .= '</tr>';
                  		}
                  		$template_table .= '</table>';	
                  		
                  		  // Get all roles
                  		$result = $modx->db->select("name, id", $modx->db->config['table_prefix']."user_roles", '', 'name ASC');
                  		$all_roles = $modx->db->makeArray( $result );
                  		$roles_table = '<table>';
                  		$roles_table .= '<tr><th class="gridHeader">Role name</th><th class="gridHeader">ID</th></tr>';
                  		foreach ($all_roles as $count=>$role) {
                  			$class = ($count % 2) ? 'gridItem':'gridAltItem';
                  			$roles_table .= '<tr>';
                  			$roles_table .= '<td class="'.$class.'">'.$role['name'].'</td>';
                  			$roles_table .= '<td class="'.$class.'">'.$role['id'].'</td>';
                  			$roles_table .= '</tr>';
                  		}
                  		$roles_table .= '</table>';
                  	
                  		// Load the jquery library
                  		$output = '<script src="'.$js_url.'" type="text/javascript" charset="utf-8"></script>';
                  		
                  		$output .= '<script type="text/javascript"> var $j = jQuery.noConflict();' . "\n";
                  		$output .= "mm_lastTab = 'tabEvents'; \n";
                  		$e->output($output);
                  		mm_createTab('Roles & Templates', 'rolestemplates', '', '', '<p>These are the IDs for current roles and templates in your site.</p>'.$template_table.'<p> </p>'.$roles_table);				
                  		$e->output('</script>');	
                  	} 
                  	
                  } else if ($e->name == 'OnDocFormRender') {
                  
                      // Include the JQuery call
                      $e->output( '
                  		<!-- ManagerManager Plugin :: Start -->
                  		<!-- This document is using template: '. $mm_current_page['template'] .' -->
                  		<!-- You are logged into the following role: '. $mm_current_page['role'] .' -->
                  				
                  		<script type="text/javascript" charset="utf-8">
                  		  $j = jQuery.noConflict();
                  			mm_lastTab = "tabGeneral"; 
                  			mm_sync_field_count = 0;
                  			synch_field = new Array();
                  		
                              jQuery(document).ready(function() {
                  			');
                  	
                  	// Get the JS for the changes
                      make_changes();    
                      // Close it off
                      $e->output('	
                  	
                  			  // Misc tidying up
                  			
                  			  // General tab table container is too narrow for receiving TVs -- make it a bit wider
                  			$j("div#tabGeneral table").attr("width", "550");
                  	
                  			// if template variables are empty, remove their section
                  			var inputs = $j("div.tmplvars input").length;
                  			var selects = $j("div.tmplvars select").length;
                  			var textareas = $j("div.tmplvars textarea").length;
                  			if ((inputs + selects + textareas) == 0) {
                  				$j("div.tmplvars").hide();	// Still contains an empty table and some dividers
                  				$j("div.sectionHeader:contains(\'Template Variables\')").hide(); // This will only work for English
                  			}
                  	
                  			// Hide the loading mask
                  			$j("#loadingmask").hide();
                              });
                  		</script>
                  		<!-- ManagerManager Plugin :: End -->
                  		');
                  }
                  
                  ?>
                    • 22797
                    • 134 Posts
                    This is a great plugin! (and thanks to Rachael for fixing the bugs). I needed to be able to set default values for other fields, but only pub_date and unpub_date were supported, so I added code to allow more of them to accept default values. I have NOT tested this extensively, but it does work for menuindex, which was my reason for adding the extra functionality. Place this code at about line 91 (in Rachael’s revised code above):

                    		case 'menuindex':
                    			$output .= '$("input[@name=menuindex]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'pagetitle':
                    			$output .= '$("input[@name=pagetitle]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'longtitle':
                    			$output .= '$("input[@name=longtitle]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'description':
                    			$output .= '$("input[@name=description]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'alias':
                    			$output .= '$("input[@name=alias]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'link_attributes':
                    			$output .= '$("input[@name=link_attributes]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'introtext':
                    			$output .= '$("input[@name=introtext]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'menutitle':
                    			$output .= '$("input[@name=menutitle]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'menuindex':
                    			$output .= '$("input[@name=menuindex]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'show_in_menu':
                    			$output .= '$("input[@name=show_in_menu]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'is_folder':
                    			$output .= '$("input[@name=is_folder]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'is_richtext':
                    			$output .= '$("input[@name=is_richtext]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'log':
                    			$output .= '$("input[@name=log]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'published':
                    			$output .= '$("input[@name=published]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    
                    		case 'pub_date':
                    			$new_value = ($new_value=='') ? date("d-m-Y H:i:s") : $new_value;
                    			$output .= '$("input[@name=pub_date]").val("'.htmlentities($new_value).'"); '."\n";
                    		break;
                    		
                    		case 'unpub_date':
                    			$new_value = ($new_value=='') ? date("d-m-Y H:i:s") : $new_value;
                    			$output .= '$("input[@name=unpub_date]").val("'.htmlentities($new_value).'"); '."\n";
                    		break;
                    		
                    		case 'searchable':
                    			$output .= '$("input[@name=searchable]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'cacheable':
                    			$output .= '$("input[@name=cacheable]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'clear_cache':
                    			$output .= '$("input[@name=clear_cache]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'content_type':
                    			$output .= '$("input[@name=content_type]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'content_dispo':
                    			$output .= '$("input[@name=content_dispo]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'keywords':
                    			$output .= '$("input[@name=keywords]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'metatags':
                    			$output .= '$("input[@name=metatags]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		case 'content':
                    			$output .= '$("input[@name=content]").val("'.htmlentities($value).'"); '."\n";
                    		break;
                    		
                    		
                    		
                    		default:
                    			return;
                    		break;
                    	}	
                    	$e->output($output . "\n");	
                    }
                    

                      • 21056
                      • 327 Posts
                      Thanks for your feedback. I’ve been away last week but I’ll take a look at these and get them tested and incorporated!

                        Author: ManagerManager plugin - customise your ModX manager interface

                        Rckt - web development, Sheffield, UK

                      This discussion is closed to further replies. Keep calm and carry on.