#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Or read it online: http:	//www.gnu.org/licenses/licenses.html#GPL
#
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
if (!isset($gCms)) {
    exit;
}
$templates = cge_template_utils::get_templates_by_prefix();
if (!$this->CheckPermission('Manage Uploads')) {
    // get the current category for the filter
    $curcategory = isset($params['curcategory']) ? $params['curcategory'] : '';
    if (isset($params['submitcategory'])) {
        $curcategory = isset($params['input_category']) ? $params['input_category'] : '';
    }
    // are we uploading a file
    if (isset($params['submitupload'])) {
        $params['category_id'] = $curcategory;
        $ret = $this->AttemptUpload($id, $params, $returnid);
        if ($ret[0] == false) {
            $this->_DisplayErrorPage($id, $params, $returnid, $ret[1]);
            return;
        }
    }
 function _DisplayTemplateList(&$module, $id, $returnid, $prefix, $defaulttemplatepref, $active_tab, $defaultprefname, $title, $info = '', $destaction = 'defaultadmin')
 {
     // we're gonna allow multiple templates here
     // but we're gonna prefix them all with something
     $smarty = cmsms()->GetSmarty();
     $falseimage1 = cmsms()->variables['admintheme']->DisplayImage('icons/system/false.gif', 'make default', '', '', 'systemicon');
     $trueimage1 = cmsms()->variables['admintheme']->DisplayImage('icons/system/true.gif', 'default', '', '', 'systemicon');
     $alltemplates = cge_template_utils::get_templates_by_prefix($module, $prefix, true);
     $rowarray = array();
     $rowclass = 'row1';
     foreach ($alltemplates as $onetemplate) {
         if ($prefix . $onetemplate == $defaulttemplatepref) {
             continue;
         }
         // don't show the system default.
         // 	if( !preg_match("/^$prefix/", $onetemplate ) )
         // 	  {
         // 	    continue;
         // 	  }
         $tmp = $onetemplate;
         $row = new StdClass();
         $row->name = $this->_module->CreateLink($id, 'edittemplate', $returnid, $tmp, array('template' => $tmp, 'destaction' => $destaction, 'cg_activetab' => $active_tab, 'title' => $title, 'info' => $info, 'prefix' => $prefix, 'modname' => $module->GetName(), 'moddesc' => $module->GetFriendlyName(), 'mode' => 'edit'));
         $row->rowclass = $rowclass;
         $default = $module->GetPreference($defaultprefname) == $tmp ? true : false;
         if ($default) {
             $row->default = $trueimage1;
         } else {
             $row->default = $this->_module->CreateLink($id, 'makedefaulttemplate', $returnid, $falseimage1, array('template' => $tmp, 'destaction' => $destaction, 'defaultprefname' => $defaultprefname, 'modname' => $module->GetName(), 'cg_activetab' => $active_tab));
         }
         $row->editlink = $this->_module->CreateImageLink($id, 'edittemplate', $returnid, $this->_module->Lang('prompt_edittemplate'), 'icons/system/edit.gif', array('template' => $tmp, 'destaction' => $destaction, 'cg_activetab' => $active_tab, 'prefix' => $prefix, 'title' => $title, 'info' => $info, 'modname' => $module->GetName(), 'moddesc' => $module->GetFriendlyName(), 'mode' => 'edit'));
         if ($default) {
             $row->deletelink = ' ';
         } else {
             $row->deletelink = $this->_module->CreateImageLink($id, 'deletetemplate', $returnid, $this->_module->Lang('prompt_deletetemplate'), 'icons/system/delete.gif', array('template' => $onetemplate, 'prefix' => $prefix, 'modname' => $module->GetName(), 'destaction' => $destaction, 'cg_activetab' => $active_tab), '', $this->_module->Lang('areyousure'));
         }
         array_push($rowarray, $row);
         $rowclass == "row1" ? $rowclass = "row2" : ($rowclass = "row1");
     }
     $smarty->assign('parent_module_name', $module->GetFriendlyName());
     $smarty->assign('items', $rowarray);
     $smarty->assign('nameprompt', $this->_module->Lang('prompt_name'));
     $smarty->assign('defaultprompt', $this->_module->Lang('prompt_default'));
     $smarty->assign('newtemplatelink', $this->_module->CreateImageLink($id, 'edittemplate', $returnid, $this->_module->Lang('prompt_newtemplate'), 'icons/system/newobject.gif', array('prefix' => $prefix, 'destaction' => $destaction, 'cg_activetab' => $active_tab, 'modname' => $module->GetName(), 'moddesc' => $module->GetFriendlyName(), 'title' => $title, 'info' => $info, 'mode' => 'add', 'defaulttemplatepref' => $defaulttemplatepref), '', '', false));
     $smarty->assign($this->_module->CreateFormEnd());
     return $this->_module->ProcessTemplate('listtemplates.tpl');
 }
 /**
  * Create a dropdown of all templates beginning with the specified prefix
  *
  * @deprecated
  * @param string $id The module action id
  * @param string $name The name for the input element.
  * @param string $prefix The optional prefix
  * @param string $selectedvalue The default value for the input element
  * @param string $addtext
  * @return string
  */
 function CreateTemplateDropdown($id, $name, $prefix = '', $selectedvalue = -1, $addtext = '')
 {
     return cge_template_utils::create_template_dropdown($id, $name, $prefix, $selectedvalue, $addtext);
 }