whups mods...

Gary Weinreb <[email protected]>
Newsgroups gmane.comp.horde.whups
Message-ID <1037771391.3ddb227f28964@studioboss>
OK. I've done this a bit differently than suggested, but hopefully this will
simplify things.  It did for me.  I've included only those portions that I've
added or changed.  Apparently I have as much to learn about cvs
as I suspected, which is a lot, and more to learn about diff than I thought...

Attached are 4 diff files, all for whups.  One for each of admin.php,
lib/Admin.php, lib/Create.php, lib/Driver/sql.php.

These are against HEAD of 11/19, late afternoon.  Without the ORDER BY clause
that Chuck objected to...  I re-read through the CODING_STANDARDS, and I think
I'm in compliance.  If not please let me know where I'm off...  I'm spending
more time this week pulling these diff's together and trying to keep my changes
up with HEAD, then actually coding....  Not good...

Any suggestions on how to better organize myself to keep up and remain
productive would be appreciated...  I'm using GNU's CVS client on a Win2k
workstation for my HEAD updates, and haven't really gotten my linux cvs
configured correctly to work with ya'll's repository...  I think that'll help...

I hope these will be useful.  The attributes stuff looks really interesting, and
if you like, the next phase of my programming I can include the attributes into
this "merging" mechanism from one type to another...

Regards,
Gary

-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/


-- 
Whups mailing list
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]
Admin.php.diff (application/octet-stream, 2.8 KB)
--- /home/tmp/HORDE_HEAD/whups/lib/Admin.php	Tue Nov 19 18:58:33 2002
+++ whups/lib/Admin.php	Wed Nov 20 00:03:38 2002
@@ -284,7 +284,7 @@

         parent::Horde_Form($vars, 'edittypestep1form');

-        $types = $backend->getAllTypes();
+        $types = $backend->getAllTypesButDefault();
         if (count($types) > 0) {
             $ttype = _getEnumType($types);
         } else {
 

+class CopyDefaultStatesForm extends Horde_Form {
+
+    function CopyDefaultStatesForm(&$vars)
+     {
+		global $backend;
+		parent::Horde_Form($vars, 'copydefaultstatesform');
+		$this->addHidden('', 'type', _getIntType(), true, true);
+
+		$defaultsources = $backend->getAllDefaultTypes();
+		$dtypes = array();
+		$index  = 1;
+        foreach ($defaultsources as $key => $typename) {
+            $dtypes[$index][1] = ($key);
+            $dtypes[$index][2] = ($typename);
+			$index++;
+        }
+
+		$defaultsourcecount = count($dtypes);
+		FOR ($index=1; $index <= $defaultsourcecount; $index++) {
+			$dtype_id = $dtypes[$index][1];
+			$dtype    = $dtypes[$index][2];
+        	$type = $vars->getVar('type');
+			// IF the default type is not the same one we are editing
+			IF ($dtype_id != $type) {
+				$states = $backend->getStates($dtype_id);
+	        	$statetype = _getSetType($states);
+	        	$tstates = &$this->addVariable(_("States for '" . $dtype . "'"), 'state', $statetype, false, true);
+	        	$tstates->setDefault(array_keys($states));
+	        	$this->addVariable(_("...merge above States..."), "MERGE_" . $dtype_id, _getBooleanType(), false);
+			}	
+		}
+    }
+}


+class CopyDefaultPrioritiesForm extends Horde_Form {
+
+    function CopyDefaultPrioritiesForm(&$vars)
+    {
+
+        global $backend;
+        parent::Horde_Form($vars, 'copydefaultprioritiesform');
+		$this->addHidden('', 'type', _getIntType(), true, true);
+
+		$defaultsources = $backend->getAllDefaultTypes();
+        $dtypes = array();
+		$index  = 1;
+        foreach ($defaultsources as $key => $typename) {
+            $dtypes[$index][1] = ($key);
+            $dtypes[$index][2] = ($typename);
+	    	$index++;
+        }
+
+		$defaultsourcecount = count($dtypes);
+		FOR ($index=1; $index <= $defaultsourcecount; $index++) {
+			$dtype_id = $dtypes[$index][1];
+			$dtype    = $dtypes[$index][2];
+        	$type = $vars->getVar('type');
+			// IF the default type is not the same one we are editing
+			IF ($dtype_id != $type) {
+				$priorities = $backend->getPriorities($dtype_id);
+	        	$prioritytype = _getSetType($priorities);
+	        	$tpriorities = &$this->addVariable(_("Priorities for '" . $dtype . "'"), 'priority', $prioritytype, false, true);
+	        	$tpriorities->setDefault(array_keys($priorities));
+	        	$this->addVariable(_("...merge above Priorities..."), "MERGE_" . $dtype_id, _getBooleanType(), false);
+			}	
+		}
+    }
+}
Create.php.diff (application/octet-stream, 2.9 KB)
--- /home/tmp/HORDE_HEAD/whups/lib/Create.php	Tue Nov 19 18:58:33 2002
+++ whups/lib/Create.php	Tue Nov 19 22:32:00 2002
@@ -44,6 +44,8 @@
 
         parent::Horde_Form($vars, 'createstep2form', null, $vars);
 
+	
+		$module = $vars->getVar('module');
         $types = $backend->getTypes($vars->getVar('module'));
         $info  = $backend->getModule($vars->getVar('module'));
         if (count($types) == 0) {
@@ -61,6 +63,10 @@
                 $vtype = _getEnumType($versions);
             }
             $this->addVariable(_("Module Version"), 'version', $vtype, true);
+	    	if (Auth::isAdmin()) {
+	   			$versionlink = _getLinkType(array('text' => _("Edit the versions for this module"), 'url' => Horde::addParameter(Horde::applicationUrl('admin.php?formname=editversionstep1form'), 'module', $module)));
+	   			$this->addVariable('', 'link', $versionlink, false, true);
+	    	}
         }
     }
 
@@ -79,6 +85,10 @@
         $module = $vars->getVar('module');
         $info = $backend->getModule($module);
 
+	    if (Auth::isAdmin()) {
+	   		$versionlink = _getLinkType(array('text' => _("Edit the versions for this module"), 'url' => Horde::addParameter(Horde::applicationUrl('admin.php?formname=editversionstep1form'), 'module', $module)));
+	   		$this->addVariable('', 'link', $versionlink, false, true);
+	    }
         if (!empty($info['subjectlist'])) 
             $subjects = $backend->getModleSubjectNames($module);
             $subtype = _getEnumType($subjects);
@@ -94,16 +104,29 @@
         }
 
         $priorities = $backend->getPriorities($vars->getVar('type'));
+        if (count($priorities) == 0) {
+            $prioritiestype = _getInvalidType(_("It is required that you specify a priority, but there are no priorities associated with this type. Until priorities are created for this type, you will not be able to create tickets."));
+        } else {
+            $prioritiestype = _getEnumType($priorities);
+        }
 
-        $statetype = _getEnumType($states);
-        $prioritiestype = _getEnumType($priorities);
+        IF (count($states) == 0) {
+			$statetype = _getInvalidType(_("It is required that you specify a state, but there are no states associated with this type. Until states are created for this type, you will not be able to create tickets."));
+		} else {
+			$statetype = _getEnumType($states);
+		}
 
         $this->addVariable(_("Ticket State"), 'state', $statetype, true);
-        $this->addVariable(_("Priority"), 'priority', $prioritiestype, true);
+		IF (Auth::isAdmin()) {
+	   		$this->addVariable('', 'link', $statelink, false, true);
+		}
+       	$this->addVariable(_("Priority"), 'priority', $prioritiestype, true);
+		IF (Auth::isAdmin()) {
+			$this->addVariable('', 'link', $prioritylink, false, true);
+		}
         $this->addVariable(_("Subject"), 'summary', $subtype, true);
         $this->addVariable(_("Description"), 'comment', _getLongTextType(), false);
     }
 }
admin.php.diff (application/octet-stream, 6.9 KB)
--- /home/tmp/HORDE_HEAD/whups/admin.php	Tue Nov 19 18:58:33 2002
+++ whups/admin.php	Tue Nov 19 23:47:11 2002
@@ -28,6 +28,8 @@
     'EditTypeStep2Form',
     'DeleteTypeForm',
     'AddStateForm',
+    'CopyDefaultStatesForm',
+    'CopyDefaultPrioritiesForm',
     'EditStateStep1Form',
     'EditStateStep2Form',
     'DeleteStateForm',
@@ -413,7 +415,17 @@
             $RENDERER->submit(_("Add State"));
             $RENDERER->end();
             $form2->close($RENDERER);
+
+            $form3 = &_getCopyDefaultStatesForm($vars);
+            $form3->open($RENDERER, $vars, 'admin.php', 'post');
+            $RENDERER->beginActive(sprintf(_("Merge Default States into '%s'"), $typename));
+            $RENDERER->renderFormActive($form3, $vars);
+            $RENDERER->submit(_("Merge States"));
+            $RENDERER->end();
+            $form3->close($RENDERER);
+
         } else {
+
             _open();
 
             $form->open($RENDERER, $vars, 'admin.php', 'post');
@@ -425,6 +437,59 @@
         }
         break;
 
+    case 'copydefaultstatesform':
+
+        $whups_admin_form = 'type';
+        $form = &_getCopyDefaultStatesForm($vars);
+        $form->validate($vars);
+		// Target Type
+        $ttype_id= ($vars->getVar('type'));
+
+        if ($vars->getVar('submitbutton')) {
+			$defaultsources = $backend->getAllDefaultTypes();
+       		foreach ($defaultsources as $stype_id => $stype) {
+				$merge = "MERGE_" . $stype_id;
+       			if ($vars->getVar($merge)) {
+					// merge this type
+       				$result = $backend->MergeDefaultStates($stype_id, $ttype_id);
+       				if (!PEAR::isError($result)) {
+       					$notification->push(sprintf(_("%s States have been successfully merged from '%s'."),$result, $stype), 'horde.success');
+					} else {
+           				$notification->push(sprintf(_("There was an error merging the states: %s."), $result->getMessage()), 'horde.error');
+           			}
+				}
+ 	    	}
+        	_open();
+	
+    	   	$form1 = &_getEditStateStep1Form($vars);
+       	$typename = $backend->getType($vars->getVar('type'));
+       	$typename = $typename['name'];
+       	$form1->open($RENDERER, $vars, 'admin.php', 'post');
+	    	$RENDERER->beginActive(sprintf(_("Edit States for '%s' %s"), $typename, _("- Stage 1")));
+       	$RENDERER->renderFormActive($form1, $vars);
+       	$RENDERER->submit(_("Edit State"));
+       	$RENDERER->submit(_("Delete State"));
+       	$RENDERER->end();
+       	$form1->close($RENDERER);
+	
+    	   	$form2 = &_getAddStateForm($vars);
+    	   	$form2->open($RENDERER, $vars, 'admin.php', 'post');
+    	   	$RENDERER->beginActive(sprintf(_("Add State for '%s'"), $typename));
+    	   	$RENDERER->renderFormActive($form2, $vars);
+    	   	$RENDERER->submit(_("Add State"));
+    	   	$RENDERER->end();
+    	   	$form2->close($RENDERER);
+
+    	   	$form3 = &_getCopyDefaultStatesForm($vars);
+    	   	$form3->open($RENDERER, $vars, 'admin.php', 'post');
+    	   	$RENDERER->beginActive(sprintf(_("Merge Default States into '%s'"), $typename));
+    	   	$RENDERER->renderFormActive($form3, $vars);
+    	   	$RENDERER->submit(_("Merge States"));
+    	   	$RENDERER->end();
+       	$form3->close($RENDERER);
+       	}
+		break;
+
     case 'editstatestep1form':
         $whups_admin_form = 'type';
         $form1 = &_getEditStateStep1Form($vars);
@@ -448,7 +513,17 @@
             $RENDERER->submit(_("Add State"));
             $RENDERER->end();
             $form2->close($RENDERER);
+
+            $form3 = &_getCopyDefaultStatesForm($vars);
+            $form3->open($RENDERER, $vars, 'admin.php', 'post');
+            $RENDERER->beginActive(sprintf(_("Merge Default States into '%s'"), $typename));
+            $RENDERER->renderFormActive($form3, $vars);
+            $RENDERER->submit(_("Merge States"));
+            $RENDERER->end();
+            $form3->close($RENDERER);
+
         } else {
+
             $form1->validate($vars);
 
             _open();
@@ -644,6 +719,59 @@
         }
         break;
 
+    case 'copydefaultprioritiesform':
+
+        $whups_admin_form = 'type';
+        $form = &_getCopyDefaultPrioritiesForm($vars);
+        $form->validate($vars);
+		// Target Type
+        $ttype_id= ($vars->getVar('type'));
+
+        if ($vars->getVar('submitbutton')) {
+        	// Merge from default Types that are in the $vars .
+			$defaultsources = $backend->getAllDefaultTypes();
+       		foreach ($defaultsources as $stype_id => $stype) {
+				$merge = "MERGE_" . $stype_id;
+           		if ($vars->getVar($merge)) {
+					// merge this type
+           			$result = $backend->MergeDefaultPriorities($stype_id, $ttype_id);
+           			if (!PEAR::isError($result)) {
+           				$notification->push(sprintf(_("%s Priorities have been successfully merged from '%s'."),$result, $stype), 'horde.success');
+					} else {
+                		$notification->push(sprintf(_("There was an error merging the Priorities: %s."), $result->getMessage()), 'horde.error');
+            		}
+				}
+ 	    	}
+        	_open();
+        	$form1 = &_getEditPriorityStep1Form($vars);
+        	$typename = $backend->getType($vars->getVar('type'));
+        	$typename = $typename['name'];
+        	$form1->open($RENDERER, $vars, 'admin.php', 'post');
+        	$RENDERER->beginActive(sprintf(_("Edit Priorities for '%s' %s"), $typename, _("- Stage 1")));
+        	$RENDERER->renderFormActive($form1, $vars);
+        	$RENDERER->submit(_("Edit Priority"));
+        	$RENDERER->submit(_("Delete Priority"));
+        	$RENDERER->end();
+        	$form1->close($RENDERER);
+
+        	$form2 = &_getAddPriorityForm($vars);
+        	$form2->open($RENDERER, $vars, 'admin.php', 'post');
+        	$RENDERER->beginActive(sprintf(_("Add Priority for '%s'"), $typename));
+        	$RENDERER->renderFormActive($form2, $vars);
+        	$RENDERER->submit(_("Add Priority"));
+        	$RENDERER->end();
+        	$form2->close($RENDERER);
+
+        	$form3 = &_getCopyDefaultPrioritiesForm($vars);
+        	$form3->open($RENDERER, $vars, 'admin.php', 'post');
+        	$RENDERER->beginActive(sprintf(_("Merge Default Priorities into '%s'"), $typename));
+        	$RENDERER->renderFormActive($form3, $vars);
+        	$RENDERER->submit(_("Merge Priorities"));
+        	$RENDERER->end();
+        	$form3->close($RENDERER);
+    	}
+		break;
+
     case 'editprioritystep1form':
         _open();
 
@@ -667,6 +795,15 @@
             $RENDERER->submit(_("Add Priority"));
             $RENDERER->end();
             $form2->close($RENDERER);
+
+            $form3 = &_getCopyDefaultPrioritiesForm($vars);
+            $form3->open($RENDERER, $vars, 'admin.php', 'post');
+            $RENDERER->beginActive(sprintf(_("Merge Default Priorities into '%s'"), $typename));
+            $RENDERER->renderFormActive($form3, $vars);
+            $RENDERER->submit(_("Merge Priorities"));
+            $RENDERER->end();
+            $form3->close($RENDERER);
+
         } else {
             $form1->validate($vars);
sql.php.diff (application/octet-stream, 2.1 KB)
--- /home/tmp/HORDE_HEAD/whups/lib/Driver/sql.php	Tue Nov 19 18:58:34 2002
+++ whups/lib/Driver/sql.php	Tue Nov 19 22:39:59 2002



+    function getAllTypesButDefault()
+    {
+        return $this->_getAssoc('SELECT type_id, type_name FROM whups_types WHERE LEFT(type_name,1) != "_" ORDER BY type_name');
+    }
+
+    function getAllDefaultTypes()
+    {
+        return $this->_getAssoc('SELECT type_id, type_name FROM whups_types WHERE LEFT(type_name,1) = "_" ORDER BY type_name');
+    }



+    function MergeDefaultStates($stype, $ttype)
+    {
+		$mergestates = $this->_getAssoc("SELECT state_name, state_description, state_category FROM whups_states WHERE type_id = $stype");
+		$count = 0;
+		FOREACH ($mergestates AS $key => $value) {
+			$state_name = $key;
+			FOREACH ($value AS $name) {
+				$state_description = $value[0];
+				$state_category =    $value[1];
+			}
+			//make sure that we don't already have this one....		
+			$exists = $this->_getOne("SELECT state_id FROM whups_states WHERE type_id = " . $this->_db->quote($ttype) . " AND state_name = " . $this->_db->quote( $state_name));
+			IF (EMPTY($exists)) {
+				$this->addState($ttype, $state_name, $state_description, $state_category);
+				$count++;
+			}
+		}
+		return $count;
+    }



+    function getDefaultSource($type)
+ 	 {
+		$typename = $this->_getOne("SELECT type_name FROM whups_types WHERE type_id = $type");
+		return $typename ;
+    }



+    function MergeDefaultPriorities($stype, $ttype)
+    {
+		$mergepriorities = $this->_getAssoc("SELECT priority_name, priority_description FROM whups_priorities WHERE type_id = $stype");
+		$count = 0;
+		FOREACH ($mergepriorities AS $key => $value) {
+			$priority_name = $key;
+			$priority_description = $value;
+			//make sure that we don't already have this one....		
+			$exists = $this->_getOne("SELECT priority_id FROM whups_priorities WHERE type_id = " . $this->_db->quote($ttype) . " AND priority_name = " . $this->_db->quote( $priority_name));
+			IF (EMPTY($exists)) {
+				$this->addPriority($ttype, $priority_name, $priority_description);
+				$count++;
+			}
+		}
+		return $count;
+    }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.