From: Alan Jack Pippin <ajp@pippin.(none)>
Date: Tue, 14 Aug 2007 05:25:09 +0000 (-0600)
Subject: Created new assignment tool. Revamped activity tool to use the assignments.
X-Git-Tag: release_0_1_0~26
X-Git-Url: http://git.pippins.net/%7Blink_activity%7D?a=commitdiff_plain;h=ec15c903b3ffd8a47a26c57bf4265403af18b4e2;p=eq%2F.git

Created new assignment tool. Revamped activity tool to use the assignments.
---

diff --git a/inc/class.eq.inc.php b/inc/class.eq.inc.php
index ab48656..ac82465 100644
--- a/inc/class.eq.inc.php
+++ b/inc/class.eq.inc.php
@@ -55,7 +55,9 @@ class eq
      'schedule'   => True,
      'admin'      => True,
      'email_appt' => True,
-     'send_ical_appt' => True
+     'send_ical_appt' => True,
+     'assign_view'    => True,
+     'assign_update'  => True,
      );
  
   function eq()
@@ -125,6 +127,9 @@ class eq
       $link_data['menuaction'] = 'eq.eq.act_list';
       $this->t->set_var('link_activity',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
       $this->t->set_var('lang_activity','Activities');
+      $link_data['menuaction'] = 'eq.eq.assign_view';
+      $this->t->set_var('link_assignment',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
+      $this->t->set_var('lang_assignment','Assignments');
       $link_data['menuaction'] = 'eq.eq.par_view';
       $this->t->set_var('link_participation',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
       $this->t->set_var('lang_participation','Participation');
@@ -571,6 +576,7 @@ class eq
       
       $this->t->set_var('lang_name','Activity Name');
       $this->t->set_var('lang_date','Date');
+      $this->t->set_var('lang_notes','Description');
       
       $sql = "SELECT * FROM eq_activity ORDER BY date DESC";
       $this->db->query($sql,__LINE__,__FILE__);
@@ -579,9 +585,18 @@ class eq
       $i = 0;
       while ($this->db->next_record())
 	{
-	  $activity_list[$i]['name'] = $this->db->f('name');
-	  $activity_list[$i]['date']  = $this->db->f('date');
 	  $activity_list[$i]['activity']  = $this->db->f('activity');
+	  $activity_list[$i]['assignment'] = $this->db->f('assignment');
+	  $activity_list[$i]['date']  = $this->db->f('date');
+	  $activity_list[$i]['notes']  = $this->db->f('notes');
+
+	  $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $activity_list[$i]['assignment'] . "'";
+	  $this->db2->query($sql,__LINE__,__FILE__);
+	  if($this->db2->next_record())
+	    {
+	      $activity_list[$i]['name'] = $this->db2->f('name');
+	      $activity_list[$i]['code'] = $this->db2->f('code');
+	    }
 	  $i++;
 	}
             
@@ -590,6 +605,9 @@ class eq
 	  $this->nextmatchs->template_alternate_row_color(&$this->t);
 	  $this->t->set_var('name',$activity_list[$i]['name']);
 	  $this->t->set_var('date',$activity_list[$i]['date']);
+	  $activity_notes = $activity_list[$i]['notes'];
+	  if(strlen($activity_notes) > 40) { $activity_notes = substr($activity_notes,0,40) . "..."; }
+	  $this->t->set_var('notes',$activity_notes);
 	  
 	  $link_data['menuaction'] = 'eq.eq.act_view';
 	  $link_data['activity'] = $activity_list[$i]['activity'];
@@ -624,13 +642,20 @@ class eq
       $sql = "SELECT * FROM eq_activity WHERE activity=" . intval(get_var('activity',array('GET','POST')));
       $this->db->query($sql,__LINE__,__FILE__);
       $this->db->next_record();
-      $this->t->set_var('name', $this->db->f('name'));
+      $this->t->set_var('assignment', $this->db->f('assignment'));
       $this->t->set_var('date', $this->db->f('date'));
       $this->t->set_var('notes', $this->db->f('notes'));
-            
+      
+      $sql = "SELECT * FROM eq_assignment WHERE assignment='" . $this->db->f('assignment') . "'";
+      $this->db2->query($sql,__LINE__,__FILE__);
+      if($this->db2->next_record())
+	{
+	  $this->t->set_var('name', $this->db2->f('name'));
+	  $this->t->set_var('code', $this->db2->f('code'));
+	}
       $this->t->set_var('lang_name','Activity Name');
       $this->t->set_var('lang_date','Date');
-      $this->t->set_var('lang_notes','Notes');
+      $this->t->set_var('lang_notes','Description');
       $this->t->set_var('lang_done','Done');
       $this->t->set_var('lang_action','View');
 
@@ -645,7 +670,7 @@ class eq
       $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
       $this->t->set_var('lang_edit','Edit');
       $this->t->set_var('cal_date',$this->db->f('date'));
-
+      
       // Now find out which elders participated in this activity
       $sql = "SELECT * FROM eq_participation WHERE activity=" . intval(get_var('activity',array('GET','POST')));
       $this->db->query($sql,__LINE__,__FILE__);
@@ -691,14 +716,14 @@ class eq
       $action = get_var('action',array('GET','POST'));
       $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.act_list'));
       $activity['activity'] = intval(get_var('activity',array('GET','POST')));
-
+      
       if($action == 'save')
 	{
-	  $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
+	  $activity['assignment'] = $this->db->db_addslashes(get_var('assignment',array('POST')));
 	  $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
 	  $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
 	  $this->db->query("UPDATE eq_activity set " .
-			   "   name='" . $activity['name'] .
+			   "   assignment='" . $activity['assignment'] .
 			   "', date='" . $activity['date'] . "'" .
 			   ", notes='" . $activity['notes'] . "'" .
 			   " WHERE activity=" . $activity['activity'],__LINE__,__FILE__);
@@ -720,12 +745,28 @@ class eq
 
       if($action == 'insert')
 	{
-	  $activity['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
+	  $activity['assignment'] = $this->db->db_addslashes(get_var('assignment',array('POST')));
 	  $activity['date'] = $this->db->db_addslashes(get_var('date',array('POST')));
 	  $activity['notes']= $this->db->db_addslashes(get_var('notes',array('POST')));
-	  $this->db->query("INSERT INTO eq_activity (name,date,notes) "
-			   . "VALUES ('" . $activity['name'] . "','"
+	  $this->db->query("INSERT INTO eq_activity (assignment,date,notes) "
+			   . "VALUES ('" . $activity['assignment'] . "','"
 			   . $activity['date'] . "','" . $activity['notes'] . "')",__LINE__,__FILE__);
+
+	  $sql = "SELECT * FROM eq_activity WHERE assignment='".$activity['assignment']."' "
+	     . " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
+	  $this->db->query($sql,__LINE__,__FILE__);
+	  if($this->db->next_record()) {
+	    print "activity: " . $this->db->f('activity') . "<br>";
+	    $activity['activity'] = $this->db->f('activity');
+	  }
+	  
+	  $elders = get_var('elder_name',array('POST'));
+	  foreach ($elders as $elder)
+	    {
+	      $this->db->query("INSERT INTO eq_participation (elder,activity) "
+			       . "VALUES (" . $elder . ",". $activity['activity'] . ")",__LINE__,__FILE__);
+	    }
+	  
 	  $this->act_list();
 	  return false;
 	}
@@ -734,7 +775,7 @@ class eq
 	{
 	  $activity['activity'] = 0;
 	  $this->t->set_var('cal_date',$this->jscal->input('date','','','','','','',$this->cal_options));
-	  $this->t->set_var('name','');
+	  $this->t->set_var('assignment','');
 	  $this->t->set_var('date','');
 	  $this->t->set_var('notes','');
 	  $this->t->set_var('lang_done','Cancel');
@@ -749,7 +790,8 @@ class eq
 	  $this->db->query($sql,__LINE__,__FILE__);
 	  $this->db->next_record();
 	  $this->t->set_var('cal_date',$this->jscal->input('date',$this->db->f('date'),'','','','','',$this->cal_options));
-	  $this->t->set_var('name', $this->db->f('name'));
+	  $this->t->set_var('assignment', $this->db->f('assignment'));
+	  $assignment = $this->db->f('assignment');
 	  $this->t->set_var('date', $this->db->f('date'));
 	  $this->t->set_var('notes', $this->db->f('notes'));
 	  $this->t->set_var('lang_done','Cancel');
@@ -759,6 +801,30 @@ class eq
 
 	}
 
+      // Create the assignments drop-down list
+      $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
+      $this->db->query($sql,__LINE__,__FILE__);
+      $i = 0;
+      while ($this->db->next_record())
+	{
+	  $assignments[$i]['assignment']  = $this->db->f('assignment');
+	  $assignments[$i]['name'] = $this->db->f('name');
+	  $assignments[$i]['code'] = $this->db->f('code');
+	  $i++;
+	}
+      
+      $assignment_data.= '<select name=assignment>';
+      $assignment_data.= '<option value=0></option>';  
+      for ($j=0; $j < count($assignments); $j++) {
+	$id = $assignments[$j]['assignment'];
+	$name = $assignments[$j]['name'];
+	if($assignments[$j]['assignment'] == $assignment) { $selected[$id] = 'selected="selected"'; } else { $selected[$id] = ''; }
+	$assignment_data.= '<option value='.$id.' '.$selected[$id].'>'.$name.'</option>';
+      }
+      $assignment_data.='</select>';
+      $this->t->set_var('assignment_data',$assignment_data);
+      
+      // Create elder selection boxes
       $sql = "SELECT * FROM eq_elder";
       $this->db->query($sql,__LINE__,__FILE__);
       $i=0;
@@ -805,6 +871,125 @@ class eq
       $this->save_sessiondata();
     }
 
+    function assign_view()
+    {
+      $this->t->set_file(array('assign_view_t' => 'assign_view.tpl'));
+      $this->t->set_block('assign_view_t','assign_view','list');
+      
+      $this->t->set_var('lang_name','Assignment Name');
+      $this->t->set_var('lang_code','Code');
+      
+      $sql = "SELECT * FROM eq_assignment ORDER BY name ASC";
+      $this->db->query($sql,__LINE__,__FILE__);
+      $total_records = $this->db->num_rows();
+
+      $i = 0;
+      while ($this->db->next_record())
+	{
+	  $assignment_list[$i]['assignment']  = $this->db->f('assignment');
+	  $assignment_list[$i]['name'] = $this->db->f('name');
+	  $assignment_list[$i]['code'] = $this->db->f('code');
+	  $i++;
+	}
+            
+      for ($i=0; $i < count($assignment_list); $i++)
+	{	  
+	  $this->nextmatchs->template_alternate_row_color(&$this->t);
+	  $this->t->set_var('name',$assignment_list[$i]['name']);
+	  $this->t->set_var('code',$assignment_list[$i]['code']);
+	  
+	  $link_data['menuaction'] = 'eq.eq.assign_update';
+	  $link_data['assignment'] = $assignment_list[$i]['assignment'];
+	  $link_data['action'] = 'edit';
+	  $this->t->set_var('edit',$GLOBALS['phpgw']->link('/eq/index.php',$link_data));
+	  $this->t->set_var('lang_edit','Edit');
+
+	  $link_data['menuaction'] = 'eq.eq.assign_update';
+	  $link_data['assignment'] = '0';
+	  $link_data['action'] = 'add';
+	  $this->t->set_var('add','<form method="POST" action="' . $GLOBALS['phpgw']->link('/eq/index.php',$link_data)
+                           . '"><input type="submit" name="Add" value="' . 'Add Assignment' .'"></font></form>');
+
+	  $this->t->fp('list','assign_view',True);
+	}
+
+      $this->t->pfp('out','assign_view_t');
+      $this->save_sessiondata();
+    }
+
+    function assign_update()
+    {
+      $this->t->set_file(array('form' => 'assign_update.tpl'));
+      $this->t->set_block('form','add','addhandle');
+      $this->t->set_block('form','edit','edithandle');
+      $this->t->set_var('lang_done','Done');
+
+      $action = get_var('action',array('GET','POST'));
+      $this->t->set_var('done_action',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_view'));
+      $assignment['assignment'] = intval(get_var('assignment',array('GET','POST')));
+
+      if($action == 'save')
+	{
+	  $assignment['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
+	  $assignment['code'] = $this->db->db_addslashes(get_var('code',array('POST')));
+	  $this->db->query("UPDATE eq_assignment set " .
+			   "  name='" . $assignment['name'] . "'" .
+			   ", code='" . $assignment['code'] . "'" .
+			   " WHERE assignment=" . $assignment['assignment'],__LINE__,__FILE__);
+	  
+	  $this->assign_view();
+	  return false;
+	}
+
+      if($action == 'insert')
+	{
+	  $assignment['name'] = $this->db->db_addslashes(get_var('name',array('POST')));
+	  $assignment['code'] = $this->db->db_addslashes(get_var('code',array('POST')));
+	  $this->db->query("INSERT INTO eq_assignment (name,code) "
+			   . "VALUES ('" . $assignment['name'] . "','"
+			   . $assignment['code'] . "')",__LINE__,__FILE__);
+	  $this->assign_view();
+	  return false;
+	}
+      
+      if($action == 'add')
+	{
+	  $assignment['assignment'] = 0;
+	  $this->t->set_var('name','');
+	  $this->t->set_var('code','');
+	  $this->t->set_var('lang_done','Cancel');
+	  $this->t->set_var('lang_action','Adding New Assignment');
+	  $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment='
+								. $assignment['assignment'] . '&action=' . 'insert'));
+	}
+
+      if($action == 'edit')
+	{
+	  $sql = "SELECT * FROM eq_assignment WHERE assignment=" . $assignment['assignment'];
+	  $this->db->query($sql,__LINE__,__FILE__);
+	  $this->db->next_record();
+	  $this->t->set_var('name', $this->db->f('name'));
+	  $this->t->set_var('code', $this->db->f('code'));
+	  $this->t->set_var('lang_done','Cancel');
+	  $this->t->set_var('lang_action','Editing Assignment');
+	  $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.assign_update&assignment='
+								. $assignment['assignment'] . '&action=' . 'save'));
+
+	}
+      
+      $this->t->set_var('lang_reset','Clear Form');
+      $this->t->set_var('lang_add','Add Assignment');
+      $this->t->set_var('lang_save','Save Changes');
+      $this->t->set_var('edithandle','');
+      $this->t->set_var('addhandle','');
+      
+      $this->t->pfp('out','form');
+      if($action == 'edit') { $this->t->pfp('addhandle','edit'); }
+      if($action == 'add') { $this->t->pfp('addhandle','add'); }
+      
+      $this->save_sessiondata();
+    }
+
   function par_view()
     {
       $this->t->set_file(array('par_view_t' => 'par_view.tpl'));
diff --git a/templates/default/act_list.tpl b/templates/default/act_list.tpl
index 3b6eb21..d72418b 100644
--- a/templates/default/act_list.tpl
+++ b/templates/default/act_list.tpl
@@ -5,14 +5,16 @@
                 <tr>
                         <td colspan="1" align="center" bgcolor="#c9c9c9"><font face="{font}"><b>{lang_date}</b></font></td>
 			<td colspan="1" align="center" bgcolor="#c9c9c9"><font face="{font}"><b>{lang_name}</b></font></td>
+			<td colspan="1" align="center" bgcolor="#c9c9c9"><font face="{font}"><b>{lang_notes}</b></font></td>
                 </tr>
 
 <!-- BEGIN act_list -->
 
                 <tr bgcolor="{tr_color}">
                         <td><font face="{font}">{date}</font></td>
-                        <td width=60%><font face="{font}" size="{font_size}">
+                        <td width=30%><font face="{font}" size="{font_size}">
                         <a href="{view}">{name}</a></font></td>
+                        <td width=40%>{notes}</font></td>
                         <td align="center"><font face="{font}"><a href="{view}">{lang_view}</a></font></td>
                         <td align="center"><font face="{font}"><a href="{edit}">{lang_edit}</a></font></td>
                 </tr>
diff --git a/templates/default/act_update.tpl b/templates/default/act_update.tpl
index 96b4ed7..fc5107d 100644
--- a/templates/default/act_update.tpl
+++ b/templates/default/act_update.tpl
@@ -9,13 +9,13 @@
 			<td align="center" bgcolor="#c9c9c9"><font face="{font}"><b>{lang_action}:&nbsp;{name}</b></font></td>
 		</tr>
 		<tr>
-			<td align="left"><font face="{font}"><b>Name:</b>&nbsp;<input type=text size="30" name="name" value="{name}"</input></td>
+			<td align="left"><font face="{font}"><b>Name:</b>&nbsp;{assignment_data}</td>
 		</tr>
 		<tr>
 			<td align="left"><font face="{font}"><b>Date:</b>&nbsp;{cal_date}</td>
 		</tr>
 		<tr>
-			<td align="left"><font face="{font}"><b>Notes:</b></font></td>
+			<td align="left"><font face="{font}"><b>Description:</b></font></td>
 		</tr>
 		<tr>	
 			<td align="left"><font face="{font}" size="{font_size}"><textarea cols="60" rows="10" name="notes" wrap="virtual">{notes}</textarea></font></td>
diff --git a/templates/default/assign_update.tpl b/templates/default/assign_update.tpl
new file mode 100644
index 0000000..2d9adfa
--- /dev/null
+++ b/templates/default/assign_update.tpl
@@ -0,0 +1,49 @@
+<!-- BEGIN form -->
+
+{app_header}
+
+<center>
+	<form action="{actionurl}" method="POST">
+	<table border="0" width="60%" cellspacing="2" cellpadding="2">
+		<tr>
+			<td align="center" bgcolor="#c9c9c9"><font face="{font}"><b>{lang_action}:&nbsp;{name}</b></font></td>
+		</tr>
+		<tr>
+			<td align="left"><font face="{font}"><b>Name:</b>&nbsp;<input type=text size="60" name="name" value="{name}"</input></td>
+		</tr>
+		<tr>
+			<td align="left"><font face="{font}"><b>Code:</b>&nbsp;<input type=text size="12" name="code" value="{code}"</input></td>
+		</tr>
+	</table>
+
+<!-- BEGIN add -->
+	<table width="70%" border="0" cellspacing="2" cellpadding="2" align=left>
+		<tr valign="bottom">
+			<td height="50" align="right">
+				<font face="{font}"><input type="submit" name="addnote" value="{lang_save}"></font></td>
+			<td height="50" align="center">
+				<font face="{font}"><input type="reset" name="reset" value="{lang_reset}"></font></form></td>
+			<td height="50" align="center">
+				<form action="{done_action}" method="POST">
+				<font face="{font}"><input type="submit" name="done" value="{lang_done}"></font></form></td>
+		</tr>
+	</table>
+</center>
+<!-- END add -->
+
+<!-- BEGIN edit -->
+	<table width="50%" border="0" cellspacing="2" cellpadding="2" align=left>
+		<tr valign="bottom" align="left">
+			<td height="50" align="right" valign="middle">
+				<font face="{font}"><input type="submit" name="editnote" value="{lang_save}"></font>
+				</form></td>
+			<td height="50" align="center" valign="middle">
+				<form action="{done_action}" method="POST">
+				<font face="{font}"><input type="submit" name="done" value="{lang_done}"></font></form></td>
+		</tr>
+	</table>
+</center>
+
+<!-- END edit -->
+
+<!-- END form -->
diff --git a/templates/default/assign_view.tpl b/templates/default/assign_view.tpl
new file mode 100644
index 0000000..2977a95
--- /dev/null
+++ b/templates/default/assign_view.tpl
@@ -0,0 +1,26 @@
+<hr>
+<br>
+<center>
+        <table border="0" cellspacing="2" cellpadding="2">
+                <tr>
+			<td colspan="1" align="center" bgcolor="#c9c9c9"><font face="{font}"><b>{lang_code}</b></font></td>
+			<td colspan="1" align="center" bgcolor="#c9c9c9"><font face="{font}"><b>{lang_name}</b></font></td>
+                </tr>
+
+<!-- BEGIN assign_view -->
+
+                <tr bgcolor="{tr_color}">
+                        <td><font face="{font}">{code}</font></td>
+                        <td width=60%><font face="{font}" size="{font_size}">{name}</font></td>
+                        <td align="center"><font face="{font}"><a href="{view}">{lang_view}</a></font></td>
+                        <td align="center"><font face="{font}"><a href="{edit}">{lang_edit}</a></font></td>
+                </tr>
+
+<!-- END assign_view -->
+
+                <tr valign="bottom">
+                        <td colspan="5"><font face="{font}">{add}</font></td>
+                </tr>
+        </table>
+</center>
+
diff --git a/templates/default/header.tpl b/templates/default/header.tpl
index e48f324..6051332 100644
--- a/templates/default/header.tpl
+++ b/templates/default/header.tpl
@@ -17,24 +17,26 @@
                                         <a href="{link_visit}">{lang_visit}</a>
 					&nbsp;
                                         &nbsp;
-                                        <a href="{link_attendance}">{lang_attendance}</a>
+                                        <a href="{link_schedule}">{lang_schedule}</a>
 					&nbsp;
                                         &nbsp;
-                                        <a href="{link_dir}">{lang_dir}</a>
+                                        <a href="{link_attendance}">{lang_attendance}</a>
 					&nbsp;
-                                        &nbsp;
-                                        <br>
-                                        <a href="{link_org}">{lang_org}</a>
+                                        &nbsp;  
+					<br>					
+                                        <a href="{link_activity}">{lang_activity}</a>
 					&nbsp;
-                                        &nbsp;
-  					
-                                        <a href="{link_schedule}">{lang_schedule}</a>
+					&nbsp;
+					<a href="{link_participation}">{lang_participation}</a>
 					&nbsp;
                                         &nbsp;
-                                        <a href="{link_activity}">{lang_activity}</a>
+					<a href="{link_assignment}">{lang_assignment}</a>
 					&nbsp;
+                                        &nbsp;
+                                        <a href="{link_dir}">{lang_dir}</a>
 					&nbsp;
-					<a href="{link_participation}">{lang_participation}</a>
+                                        &nbsp;
+                                        <a href="{link_org}">{lang_org}</a>
 					&nbsp;
                                         &nbsp;
                                         <a href="{link_admin}">{lang_admin}</a>