Updating courses adding new file and filenames
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 27 Feb 2015 20:01:25 +0000 (15:01 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 27 Feb 2015 20:01:25 +0000 (15:01 -0500)
Toolkit/Members/Admin/EditCourses.php
Toolkit/Members/EditCourses.php
Toolkit/Members/templates/addCourse.tpl
Toolkit/Members/templates/editCourse.tpl

index 356c315..4ca7438 100644 (file)
@@ -458,6 +458,8 @@ class AddAdminCourse extends Toolkit_FormBuilder
             'name'    => 'image',
             'display' => 'Upload a Course Photo / Image',
         );
+
+        /* Course File One */
         $e[] = array(
             'type'    => 'checkbox',
             'req'     => false,
@@ -481,12 +483,50 @@ class AddAdminCourse extends Toolkit_FormBuilder
             'name'    => 'file',
             'display' => 'Upload a Course File',
         );
+        $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'filename',
+            'display' => 'File Name',
+            'opts'    => array('class' => 'text')
+        );
+        /* Course File Two */
+        $e[] = array(
+            'type'    => 'checkbox',
+            'req'     => false,
+            'name'    => 'remove_file2_rmv',
+            'display' => 'Remove File 2',
+        );
+        $e[] = array(
+            'type'    => 'static',
+            'req'     => false,
+            'name'    => 'curr_file2',
+            'display' => 'Current File 2',
+        );
+        $e[] = array(
+            'type'    => 'hidden',
+            'req'     => false,
+            'name'    => 'curr_file2_rmv',
+        );
+        $e[] = array(
+            'type'    => 'file',
+            'req'     => false,
+            'name'    => 'file2',
+            'display' => 'Upload a Course File 2',
+        );
+        $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'file2name',
+            'display' => 'File 2 Name',
+            'opts'    => array('class' => 'text')
+        );
+
         $e[] = array(
             'type' => 'header',
             'req' => false,
             'name' => 'GolfingHdr',
-            'display' => 'Golf Course Information',
-            //'col2' => true
+            'display' => 'Golf Course Information'
         );
         $e[] = array(
             'type'    => 'text',
@@ -587,6 +627,15 @@ class AddAdminCourse extends Toolkit_FormBuilder
             'reset'      => false,
             'force'      => false
         );
+        $r[] = array(
+            'element'    => 'file2_rmv',
+            'message'    => 'ERROR: Incorrect File Type (.pdf, .doc) only!',
+            'type'       => 'mimetype',
+            'format'     => $this->fileMimeTypes,
+            'validation' => $this->validationType,
+            'reset'      => false,
+            'force'      => false
+        );
 
         $this->setupRules($r);
     }
@@ -712,14 +761,21 @@ class AddAdminCourse extends Toolkit_FormBuilder
 
         $values['pos']       = $courses->getListSize() + 1;
         $values['image'] = $e->getValue('curr_image_rmv');
+
         $e =& $this->getElement('curr_file_rmv');
         $values['file'] = $e->getValue('curr_file_rmv');
+
+        $e =& $this->getElement('curr_file2_rmv');
+        $values['file2'] = $e->getValue('curr_file2_rmv');
+
         $values['member_id'] = $_GET['id'];
         $values['pending']   = 0;
         unset($values['MAX_FILE_SIZE'],
               $values['curr_image_rmv'],
               $values['curr_file_rmv'],
               $values['remove_img_rmv'],
+            $values['curr_file2_rmv'],
+            $values['remove_file2_rmv'],
               $values['add_rmv']);
         //echo '<pre>'.print_r($values, true).'</pre>';
         //exit;
@@ -755,6 +811,7 @@ class AddAdminCourse extends Toolkit_FormBuilder
         $this->accept($renderer);
         $this->view              = new stdClass();
         $this->view->showCurrImg = $this->showCurrImg;
+        $this->view->showCurrFile2 = $this->showCurrFile2;
         $this->view->form        = $renderer->toObject();
         $tEngine->compile($this->formTemplate);
     }
@@ -809,6 +866,24 @@ class AddAdminCourse extends Toolkit_FormBuilder
             $this->_submitValues['curr_image_rmv'] = null;
         }
     }
+    function removeOldFile($oldFile)
+    {
+        $this->deleteFile($oldFile);
+        if ($this->elementExists('curr_file_rmv')) {
+            $e =& $this->getElement('curr_file_rmv');
+            $e->setValue(null);
+            $this->_submitValues['curr_file_rmv'] = null;
+        }
+    }
+    function removeOldFile2($oldFile)
+    {
+        $this->deleteFile($oldFile);
+        if ($this->elementExists('curr_file2_rmv')) {
+            $e =& $this->getElement('curr_file2_rmv');
+            $e->setValue(null);
+            $this->_submitValues['curr_file2_rmv'] = null;
+        }
+    }
 
     //  }}}
     //  {{{ syncCurrImage()
@@ -878,6 +953,32 @@ class AddAdminCourse extends Toolkit_FormBuilder
             $this->showCurrFile = true;
         }
     }
+    protected function syncCurrFile2()
+    {
+        $delFile2 = $this->getSubmitValue('remove_file2_rmv');
+        $oldFile2 = $this->getSubmitValue('curr_file2_rmv');
+        $newFile2 = $this->getSubmitValue('file2');
+
+        if ($delFile2 && $oldFile2) {
+            $this->removeOldFile2($oldFile2);
+            unset($oldFile2);
+        } elseif ($oldFile2 && $this->validNewFile($newFile2)) {
+            $this->removeOldFile2($oldFile2);
+            unset($oldFile2);
+        }
+
+        if ($this->validNewFile($newFile2)) {
+            $fileData = $this->uploadFile('file2');
+            $file = ($fileData['name']) ? $fileData['name']: null;
+        } else {
+            $file = $oldFile2;
+        }
+
+        if ($file) {
+            $this->updateFile2Elements($file);
+            $this->showCurrFile2 = true;
+        }
+    }
     //    {{{ toHtml()
 
     /**
@@ -904,6 +1005,7 @@ class AddAdminCourse extends Toolkit_FormBuilder
         if ($this->isSubmitted()) {
             $this->syncCurrImage();
             $this->syncCurrFile();
+            $this->syncCurrFile2();
         }
 
         $this->setupRenderers($tEngine);
@@ -936,6 +1038,20 @@ class AddAdminCourse extends Toolkit_FormBuilder
         $e =& $this->getElement('curr_file_rmv');
         $e->setValue($file);
     }
+    public function updateFile2Elements($file)
+    {
+        //  Get the dimensions of the image
+        $s = MEMBER_ORIGINAL . $file;
+
+        //  Set the image to show in the element
+        $e =& $this->getElement('curr_file2');
+        $e->setText('<a href="'.$s.'"></a>');
+
+        //  updated the hidden elements value to make sure it
+        //  holds the most up-to-date image name
+        $e =& $this->getElement('curr_file2_rmv');
+        $e->setValue($file);
+    }
     /**
      * Short description for function
      *
@@ -1179,6 +1295,12 @@ class EditAdminCourse extends Toolkit_FormBuilder
         $file = '<a href="%s">File</a>';
         $defaults['curr_file'] = sprintf($file, MEMBER_ORIGINAL . $defaults['file']);
         $this->showCurrFile = $defaults['file'];
+
+        $defaults['curr_file2_rmv'] = $defaults['file2'];
+        $file2 = '<a href="%s">File 2</a>';
+        $defaults['curr_file2'] = sprintf($file2, MEMBER_ORIGINAL . $defaults['file2']);
+        $this->showCurrFile2 = $defaults['file2'];
+
         $this->setupDefaults($defaults);
     }
 
@@ -1235,6 +1357,8 @@ class EditAdminCourse extends Toolkit_FormBuilder
             'name'    => 'image',
             'display' => 'Upload a Course Photo / Image',
         );
+
+        /* File One */
         $e[] = array(
             'type'    => 'checkbox',
             'req'     => false,
@@ -1258,6 +1382,45 @@ class EditAdminCourse extends Toolkit_FormBuilder
             'name'    => 'file',
             'display' => 'Upload a Course File',
         );
+        $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'filename',
+            'display' => 'File Name',
+            'opts'    => array('class' => 'text')
+        );
+        /* FileTwoOne */
+        $e[] = array(
+            'type'    => 'checkbox',
+            'req'     => false,
+            'name'    => 'remove_file2_rmv',
+            'display' => 'Remove File 2',
+        );
+        $e[] = array(
+            'type'    => 'static',
+            'req'     => false,
+            'name'    => 'curr_file2',
+            'display' => 'Current File 2',
+        );
+        $e[] = array(
+            'type'    => 'hidden',
+            'req'     => false,
+            'name'    => 'curr_file2_rmv',
+        );
+        $e[] = array(
+            'type'    => 'file',
+            'req'     => false,
+            'name'    => 'file2',
+            'display' => 'Upload a Course File 2',
+        );
+        $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'file2name',
+            'display' => 'File 2 Name',
+            'opts'    => array('class' => 'text')
+        );
+
         $e[] = array(
             'type'    => 'text',
             'req'     => false,
@@ -1364,6 +1527,15 @@ class EditAdminCourse extends Toolkit_FormBuilder
             'reset'      => false,
             'force'      => false
         );
+        $r[] = array(
+            'element'    => 'file2_rmv',
+            'message'    => 'ERROR: Incorrect File Type (.pdf, .doc) only!',
+            'type'       => 'mimetype',
+            'format'     => $this->fileMimeTypes,
+            'validation' => $this->validationType,
+            'reset'      => false,
+            'force'      => false
+        );
 
         $this->setupRules($r);
     }
@@ -1455,12 +1627,17 @@ class EditAdminCourse extends Toolkit_FormBuilder
         $e =& $this->getElement('curr_file_rmv');
         $values['file'] = $e->getValue('curr_file_rmv');
 
+        $e =& $this->getElement('curr_file2_rmv');
+        $values['file2'] = $e->getValue('curr_file2_rmv');
+
         unset(
             $values['MAX_FILE_SIZE'],
             $values['curr_image_rmv'],
             $values['remove_img_rmv'],
             $values['curr_file_rmv'],
             $values['remove_file_rmv'],
+            $values['curr_file2_rmv'],
+            $values['remove_file2_rmv'],
             $values['add_rmv']
         );
 
@@ -1495,12 +1672,13 @@ class EditAdminCourse extends Toolkit_FormBuilder
         $renderer = new HTML_QuickForm_Renderer_ObjectFlexy($tEngine);
 
         $this->accept($renderer);
-        $this->view               = new stdClass();
-        $this->view->courseId     = $this->courseId;
-        $this->view->courseName   = $this->courseName;
-        $this->view->showCurrImg  = $this->showCurrImg;
-        $this->view->showCurrFile = $this->showCurrFile;
-        $this->view->form         = $renderer->toObject();
+        $this->view                = new stdClass();
+        $this->view->courseId      = $this->courseId;
+        $this->view->courseName    = $this->courseName;
+        $this->view->showCurrImg   = $this->showCurrImg;
+        $this->view->showCurrFile  = $this->showCurrFile;
+        $this->view->showCurrFile2 = $this->showCurrFile2;
+        $this->view->form          = $renderer->toObject();
         $tEngine->compile($this->formTemplate);
     }
 
@@ -1556,7 +1734,7 @@ class EditAdminCourse extends Toolkit_FormBuilder
     }
 
     //  }}}
-    function removeOldFile(Toolkit_Image_Server $is, $oldFile)
+    function removeOldFile($oldFile)
     {
         $this->deleteFile($oldFile);
         if ($this->elementExists('curr_file_rmv')) {
@@ -1565,6 +1743,15 @@ class EditAdminCourse extends Toolkit_FormBuilder
             $this->_submitValues['curr_file_rmv'] = null;
         }
     }
+    function removeOldFile2($oldFile)
+    {
+        $this->deleteFile($oldFile);
+        if ($this->elementExists('curr_file2_rmv')) {
+            $e =& $this->getElement('curr_file2_rmv');
+            $e->setValue(null);
+            $this->_submitValues['curr_file2_rmv'] = null;
+        }
+    }
     //  {{{ syncCurrImage()
 
     /**
@@ -1615,17 +1802,15 @@ class EditAdminCourse extends Toolkit_FormBuilder
      */
     protected function syncCurrFile()
     {
-        $is = new Toolkit_Image_Server();
-
         $delFile = $this->getSubmitValue('remove_file_rmv');
         $oldFile = $this->getSubmitValue('curr_file_rmv');
         $newFile = $this->getSubmitValue('file');
 
         if ($delFile && $oldFile) {
-            $this->removeOldFile($is, $oldFile);
+            $this->removeOldFile($oldFile);
             unset($oldFile);
         } elseif ($oldFile && $this->validNewFile($newFile)) {
-            $this->removeOldFile($is, $oldFile);
+            $this->removeOldFile($oldFile);
             unset($oldFile);
         }
 
@@ -1641,6 +1826,32 @@ class EditAdminCourse extends Toolkit_FormBuilder
             $this->showCurrFile = true;
         }
     }
+    protected function syncCurrFile2()
+    {
+        $delFile2 = $this->getSubmitValue('remove_file2_rmv');
+        $oldFile2 = $this->getSubmitValue('curr_file2_rmv');
+        $newFile2 = $this->getSubmitValue('file2');
+
+        if ($delFile2 && $oldFile2) {
+            $this->removeOldFile2($oldFile2);
+            unset($oldFile2);
+        } elseif ($oldFile2 && $this->validNewFile($newFile2)) {
+            $this->removeOldFile2($oldFile2);
+            unset($oldFile2);
+        }
+
+        if ($this->validNewFile($newFile2)) {
+            $fileData = $this->uploadFile('file2');
+            $file = ($fileData['name']) ? $fileData['name']: null;
+        } else {
+            $file = $oldFile2;
+        }
+
+        if ($file) {
+            $this->updateFile2Elements($file);
+            $this->showCurrFile2 = true;
+        }
+    }
     //    {{{ toHtml()
 
     /**
@@ -1667,6 +1878,7 @@ class EditAdminCourse extends Toolkit_FormBuilder
         if ($this->isSubmitted()) {
             $this->syncCurrImage();
             $this->syncCurrFile();
+            $this->syncCurrFile2();
         }
 
         $this->setupRenderers($tEngine);
@@ -1796,6 +2008,20 @@ class EditAdminCourse extends Toolkit_FormBuilder
         $e =& $this->getElement('curr_file_rmv');
         $e->setValue($file);
     }
+    public function updateFile2Elements($file)
+    {
+        //  Get the dimensions of the image
+        $s = MEMBER_ORIGINAL . $file;
+
+        //  Set the image to show in the element
+        $e =& $this->getElement('curr_file2');
+        $e->setText('<a href="'.$s.'"></a>');
+
+        //  updated the hidden elements value to make sure it
+        //  holds the most up-to-date image name
+        $e =& $this->getElement('curr_file2_rmv');
+        $e->setValue($file);
+    }
     //  {{{ uploadImage()
 
     /**
index 5dece66..81fa86f 100644 (file)
@@ -448,12 +448,50 @@ class AddCourse extends Toolkit_FormBuilder
             'name'    => 'file',
             'display' => 'Upload a Course File',
         );
+        $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'filename',
+            'display' => 'File Name',
+            'opts'    => array('class' => 'text')
+        );
+        /* Course File Two */
+        $e[] = array(
+            'type'    => 'checkbox',
+            'req'     => false,
+            'name'    => 'remove_file2_rmv',
+            'display' => 'Remove File 2',
+        );
+        $e[] = array(
+            'type'    => 'static',
+            'req'     => false,
+            'name'    => 'curr_file2',
+            'display' => 'Current File 2',
+        );
+        $e[] = array(
+            'type'    => 'hidden',
+            'req'     => false,
+            'name'    => 'curr_file2_rmv',
+        );
+        $e[] = array(
+            'type'    => 'file',
+            'req'     => false,
+            'name'    => 'file2',
+            'display' => 'Upload a Course File 2',
+        );
+        $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'file2name',
+            'display' => 'File 2 Name',
+            'opts'    => array('class' => 'text')
+        );
+
         $e[] = array(
             'type' => 'header',
             'req' => false,
             'name' => 'GolfingHdr',
-            'display' => 'Golf Course Information',
-            //'col2' => true
+            'display' => 'Golf Course Information'
         );
         $e[] = array(
             'type'    => 'text',
@@ -554,6 +592,15 @@ class AddCourse extends Toolkit_FormBuilder
             'reset'      => false,
             'force'      => false
         );
+        $r[] = array(
+            'element'    => 'file2_rmv',
+            'message'    => 'ERROR: Incorrect File Type (.pdf, .doc) only!',
+            'type'       => 'mimetype',
+            'format'     => $this->fileMimeTypes,
+            'validation' => $this->validationType,
+            'reset'      => false,
+            'force'      => false
+        );
 
         $this->setupRules($r);
     }
@@ -837,15 +884,24 @@ class AddCourse extends Toolkit_FormBuilder
         $courses = new Toolkit_Members_Courses(null, $id);
         $courses->setDbh($this->dbh);
         $courses->createMemberList();
+
+
         $values['pos']       = $courses->getListSize() + 1;
         $values['image'] = $e->getValue('curr_image_rmv');
+
         $e =& $this->getElement('curr_file_rmv');
         $values['file'] = $e->getValue('curr_file_rmv');
+
+        $e =& $this->getElement('curr_file2_rmv');
+        $values['file2'] = $e->getValue('curr_file2_rmv');
+
         $values['member_id'] = $GLOBALS['memberAuth']->getAuthData('member_id');
         unset($values['MAX_FILE_SIZE'],
               $values['curr_image_rmv'],
               $values['curr_file_rmv'],
               $values['remove_img_rmv'],
+            $values['curr_file2_rmv'],
+            $values['remove_file2_rmv'],
               $values['add_rmv']);
 
         $this->tableMetaData = Toolkit_Common::getTableMetaData(
@@ -881,6 +937,7 @@ class AddCourse extends Toolkit_FormBuilder
         $this->accept($renderer);
         $this->view              = new StdClass;
         $this->view->showCurrImg = $this->showCurrImg;
+        $this->view->showCurrFile2 = $this->showCurrFile2;
         $this->view->form        = $renderer->toObject();
         $this->template->compile($this->formTemplate);
     }
@@ -937,7 +994,24 @@ class AddCourse extends Toolkit_FormBuilder
             $this->_submitValues['curr_image_rmv'] = null;
         }
     }
-
+    function removeOldFile($oldFile)
+    {
+        $this->deleteFile($oldFile);
+        if ($this->elementExists('curr_file_rmv')) {
+            $e =& $this->getElement('curr_file_rmv');
+            $e->setValue(null);
+            $this->_submitValues['curr_file_rmv'] = null;
+        }
+    }
+    function removeOldFile2($oldFile)
+    {
+        $this->deleteFile($oldFile);
+        if ($this->elementExists('curr_file2_rmv')) {
+            $e =& $this->getElement('curr_file2_rmv');
+            $e->setValue(null);
+            $this->_submitValues['curr_file2_rmv'] = null;
+        }
+    }
     //  }}}
     //  {{{ syncCurrImage()
 
@@ -1007,6 +1081,32 @@ class AddCourse extends Toolkit_FormBuilder
             $this->showCurrFile = true;
         }
     }
+    protected function syncCurrFile2()
+    {
+        $delFile2 = $this->getSubmitValue('remove_file2_rmv');
+        $oldFile2 = $this->getSubmitValue('curr_file2_rmv');
+        $newFile2 = $this->getSubmitValue('file2');
+
+        if ($delFile2 && $oldFile2) {
+            $this->removeOldFile2($oldFile2);
+            unset($oldFile2);
+        } elseif ($oldFile2 && $this->validNewFile($newFile2)) {
+            $this->removeOldFile2($oldFile2);
+            unset($oldFile2);
+        }
+
+        if ($this->validNewFile($newFile2)) {
+            $fileData = $this->uploadFile('file2');
+            $file = ($fileData['name']) ? $fileData['name']: null;
+        } else {
+            $file = $oldFile2;
+        }
+
+        if ($file) {
+            $this->updateFile2Elements($file);
+            $this->showCurrFile2 = true;
+        }
+    }
     //    {{{ toHtml()
 
     /**
@@ -1031,6 +1131,7 @@ class AddCourse extends Toolkit_FormBuilder
         if ($this->isSubmitted()) {
             $this->syncCurrImage();
             $this->syncCurrFile();
+            $this->syncCurrFile2();
         }
 
         $this->setupRenderers();
@@ -1063,6 +1164,20 @@ class AddCourse extends Toolkit_FormBuilder
         $e =& $this->getElement('curr_file_rmv');
         $e->setValue($file);
     }
+    public function updateFile2Elements($file)
+    {
+        //  Get the dimensions of the image
+        $s = MEMBER_ORIGINAL . $file;
+
+        //  Set the image to show in the element
+        $e =& $this->getElement('curr_file2');
+        $e->setText('<a href="'.$s.'"></a>');
+
+        //  updated the hidden elements value to make sure it
+        //  holds the most up-to-date image name
+        $e =& $this->getElement('curr_file2_rmv');
+        $e->setValue($file);
+    }
     /**
      * Short description for function
      *
@@ -1177,6 +1292,7 @@ class EditCourse extends Toolkit_FormBuilder
      * @access protected
      */
     protected $courseId;
+    protected $courseName;
 
     /**
      * Description for protected
@@ -1331,6 +1447,12 @@ class EditCourse extends Toolkit_FormBuilder
         $file = '<a href="%s">File</a>';
         $defaults['curr_file'] = sprintf($file, MEMBER_ORIGINAL . $defaults['file']);
         $this->showCurrFile = $defaults['file'];
+
+        $defaults['curr_file2_rmv'] = $defaults['file2'];
+        $file2 = '<a href="%s">File 2</a>';
+        $defaults['curr_file2'] = sprintf($file2, MEMBER_ORIGINAL . $defaults['file2']);
+        $this->showCurrFile2 = $defaults['file2'];
+
         $this->setupDefaults($defaults);
     }
 
@@ -1387,6 +1509,8 @@ class EditCourse extends Toolkit_FormBuilder
             'name'    => 'image',
             'display' => 'Upload a Course Photo / Image',
         );
+
+        /* File One */
         $e[] = array(
             'type'    => 'checkbox',
             'req'     => false,
@@ -1410,6 +1534,45 @@ class EditCourse extends Toolkit_FormBuilder
             'name'    => 'file',
             'display' => 'Upload a Course File',
         );
+        $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'filename',
+            'display' => 'File Name',
+            'opts'    => array('class' => 'text')
+        );
+        /* FileTwoOne */
+        $e[] = array(
+            'type'    => 'checkbox',
+            'req'     => false,
+            'name'    => 'remove_file2_rmv',
+            'display' => 'Remove File 2',
+        );
+        $e[] = array(
+            'type'    => 'static',
+            'req'     => false,
+            'name'    => 'curr_file2',
+            'display' => 'Current File 2',
+        );
+        $e[] = array(
+            'type'    => 'hidden',
+            'req'     => false,
+            'name'    => 'curr_file2_rmv',
+        );
+        $e[] = array(
+            'type'    => 'file',
+            'req'     => false,
+            'name'    => 'file2',
+            'display' => 'Upload a Course File 2',
+        );
+        $e[] = array(
+            'type'    => 'text',
+            'req'     => false,
+            'name'    => 'file2name',
+            'display' => 'File 2 Name',
+            'opts'    => array('class' => 'text')
+        );
+
         $e[] = array(
             'type'    => 'text',
             'req'     => false,
@@ -1516,6 +1679,15 @@ class EditCourse extends Toolkit_FormBuilder
             'reset'      => false,
             'force'      => false
         );
+        $r[] = array(
+            'element'    => 'file2_rmv',
+            'message'    => 'ERROR: Incorrect File Type (.pdf, .doc) only!',
+            'type'       => 'mimetype',
+            'format'     => $this->fileMimeTypes,
+            'validation' => $this->validationType,
+            'reset'      => false,
+            'force'      => false
+        );
 
         $this->setupRules($r);
     }
@@ -1797,8 +1969,10 @@ class EditCourse extends Toolkit_FormBuilder
         $this->accept($renderer);
         $this->view              = new StdClass;
         $this->view->courseId    = $this->courseId;
+        $this->view->courseName    = $this->courseName;
         $this->view->showCurrImg = $this->showCurrImg;
         $this->view->showCurrFile = $this->showCurrFile;
+        $this->view->showCurrFile2 = $this->showCurrFile2;
         $this->view->form        = $renderer->toObject();
         $this->template->compile($this->formTemplate);
     }
@@ -1856,7 +2030,7 @@ class EditCourse extends Toolkit_FormBuilder
     }
 
     //  }}}
-    function removeOldFile(Toolkit_Image_Server $is, $oldFile)
+    function removeOldFile($oldFile)
     {
         $this->deleteFile($oldFile);
         if ($this->elementExists('curr_file_rmv')) {
@@ -1865,6 +2039,15 @@ class EditCourse extends Toolkit_FormBuilder
             $this->_submitValues['curr_file_rmv'] = null;
         }
     }
+    function removeOldFile2($oldFile)
+    {
+        $this->deleteFile($oldFile);
+        if ($this->elementExists('curr_file2_rmv')) {
+            $e =& $this->getElement('curr_file2_rmv');
+            $e->setValue(null);
+            $this->_submitValues['curr_file2_rmv'] = null;
+        }
+    }
 
 
     /**
@@ -1915,17 +2098,15 @@ class EditCourse extends Toolkit_FormBuilder
      */
     protected function syncCurrFile()
     {
-        $is = new Toolkit_Image_Server();
-
         $delFile = $this->getSubmitValue('remove_file_rmv');
         $oldFile = $this->getSubmitValue('curr_file_rmv');
         $newFile = $this->getSubmitValue('file');
 
         if ($delFile && $oldFile) {
-            $this->removeOldFile($is, $oldFile);
+            $this->removeOldFile($oldFile);
             unset($oldFile);
         } elseif ($oldFile && $this->validNewFile($newFile)) {
-            $this->removeOldFile($is, $oldFile);
+            $this->removeOldFile($oldFile);
             unset($oldFile);
         }
 
@@ -1941,6 +2122,32 @@ class EditCourse extends Toolkit_FormBuilder
             $this->showCurrFile = true;
         }
     }
+    protected function syncCurrFile2()
+    {
+        $delFile2 = $this->getSubmitValue('remove_file2_rmv');
+        $oldFile2 = $this->getSubmitValue('curr_file2_rmv');
+        $newFile2 = $this->getSubmitValue('file2');
+
+        if ($delFile2 && $oldFile2) {
+            $this->removeOldFile2($oldFile2);
+            unset($oldFile2);
+        } elseif ($oldFile2 && $this->validNewFile($newFile2)) {
+            $this->removeOldFile2($oldFile2);
+            unset($oldFile2);
+        }
+
+        if ($this->validNewFile($newFile2)) {
+            $fileData = $this->uploadFile('file2');
+            $file = ($fileData['name']) ? $fileData['name']: null;
+        } else {
+            $file = $oldFile2;
+        }
+
+        if ($file) {
+            $this->updateFile2Elements($file);
+            $this->showCurrFile2 = true;
+        }
+    }
     //    {{{ toHtml()
 
     /**
@@ -1965,6 +2172,7 @@ class EditCourse extends Toolkit_FormBuilder
         if ($this->isSubmitted()) {
             $this->syncCurrImage();
             $this->syncCurrFile();
+            $this->syncCurrFile2();
         }
 
         $this->setupRenderers();
@@ -2133,7 +2341,20 @@ class EditCourse extends Toolkit_FormBuilder
         $e =& $this->getElement('curr_file_rmv');
         $e->setValue($file);
     }
+    public function updateFile2Elements($file)
+    {
     //  {{{ uploadImage()
+        $s = MEMBER_ORIGINAL . $file;
+
+        //  Set the image to show in the element
+        $e =& $this->getElement('curr_file2');
+        $e->setText('<a href="'.$s.'"></a>');
+
+        //  updated the hidden elements value to make sure it
+        //  holds the most up-to-date image name
+        $e =& $this->getElement('curr_file2_rmv');
+        $e->setValue($file);
+    }
 
 
     /**
index 748e9b9..5bccc54 100644 (file)
                 {form.file.error:h}
             </div>
             {form.file.html:h}
+                <i>{form.filename.label:h}</i>
+                <div flexy:if="form.filename.error" class="req">{form.filename.error:h}</div>
+                {form.filename.html:h}
         </div>
+            <div class="coursePhoto">
+                <div flexy:if="showCurrFile2">
+                    <label>
+                        {form.remove_file2_rmv.html:h}
+                        {form.remove_file2_rmv.label:h}
+                    </label>
+
+                    <i>{form.curr_file2.label:h}</i>
+                    {form.curr_file2.html:h}
+                </div>
+                <i>{form.file2.label:h}</i>
+                <div flexy:if="form.file2.error" class="req">
+                    {form.file2.error:h}
+                </div>
+                {form.file2.html:h}
+
+                <i>{form.file2name.label:h}</i>
+                <div flexy:if="form.file2name.error" class="req">{form.file2name.error:h}</div>
+                {form.file2name.html:h}
+            </div>
         <div class="submitArea"> {form.add_rmv.html:h} </div>
     </form>
 </div>
index 3575ce5..05b0fce 100644 (file)
                     {form.file.error:h}
                 </div>
                 {form.file.html:h}
+                <i>{form.filename.label:h}</i>
+                <div flexy:if="form.filename.error" class="req">{form.filename.error:h}</div>
+                {form.filename.html:h}
+            </div>
+            <div class="coursePhoto">
+                <div flexy:if="showCurrFile2">
+                    <label>
+                        {form.remove_file2_rmv.html:h}
+                        {form.remove_file2_rmv.label:h}
+                    </label>
+
+                    <i>{form.curr_file2.label:h}</i>
+                    {form.curr_file2.html:h}
+                </div>
+                <i>{form.file2.label:h}</i>
+                <div flexy:if="form.file2.error" class="req">
+                    {form.file2.error:h}
+                </div>
+                {form.file2.html:h}
+
+                <i>{form.file2name.label:h}</i>
+                <div flexy:if="form.file2name.error" class="req">{form.file2name.error:h}</div>
+                {form.file2name.html:h}
             </div>
             <div class="submitArea">
                 {form.add_rmv.html:h}