![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: addedit.php 156 2008-04-11 15:47:40Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/departments/addedit.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 // Add / Edit Company 7 $dept_id = isset($_GET['dept_id']) ? w2PgetParam($_GET, 'dept_id', 0) : 0; 8 $company_id = isset($_GET['company_id']) ? w2PgetParam($_GET, 'company_id', 0) : 0; 9 10 // check permissions for this record 11 $perms = &$AppUI->acl(); 12 $canAuthor = $perms->checkModule('departments', 'add'); 13 $canEdit = $perms->checkModuleItem('departments', 'edit', $dept_id); 14 15 // check permissions 16 if (!$canAuthor && !$dept_id) { 17 $AppUI->redirect('m=public&a=access_denied'); 18 } 19 20 if (!$canEdit && $dept_id) { 21 $AppUI->redirect('m=public&a=access_denied'); 22 } 23 24 $countries = array('' => $AppUI->_('(Select a Country)')) + w2PgetSysVal('GlobalCountries'); 25 // load the department types 26 $types = w2PgetSysVal('DepartmentType'); 27 28 // pull data for this department 29 $q = new DBQuery; 30 $q->addTable('departments', 'dep'); 31 $q->addQuery('dep.*, company_name'); 32 $q->addJoin('companies', 'com', 'com.company_id = dep.dept_company', 'inner'); 33 $q->addWhere('dep.dept_id = ' . (int)$dept_id); 34 $drow = $q->loadHash(); 35 $q->clear(); 36 if (!$drow && $dept_id > 0) { 37 $titleBlock = new CTitleBlock('Invalid Department ID', 'departments.png', $m, $m . '.' . $a); 38 $titleBlock->addCrumb('?m=companies', 'companies list'); 39 if ($company_id) { 40 $titleBlock->addCrumb('?m=companies&a=view&company_id=' . $company_id, 'view this company'); 41 } 42 $titleBlock->show(); 43 } else { 44 ##echo $sql.db_error();## 45 $company_id = $dept_id ? $drow['dept_company'] : $company_id; 46 47 // check if valid company 48 $q = new DBQuery; 49 $q->addTable('companies', 'com'); 50 $q->addQuery('company_name'); 51 $q->addWhere('com.company_id = ' . (int)$company_id); 52 $company_name = $q->loadResult(); 53 $q->clear(); 54 if (!$dept_id && $company_name === null) { 55 $AppUI->setMsg('badCompany', UI_MSG_ERROR); 56 $AppUI->redirect(); 57 } 58 59 // collect all the departments in the company 60 $depts = array(0 => ''); 61 if ($company_id) { 62 $q = new DBQuery; 63 $q->addTable('departments', 'dep'); 64 $q->addQuery('dept_id, dept_name, dept_parent'); 65 $q->addWhere('dep.dept_company = ' . (int)$company_id); 66 $q->addWhere('dep.dept_id <> ' . $dept_id); 67 $department = new CDepartment; 68 $department->setAllowedSQL($AppUI->user_id, $q); 69 $depts = $q->loadArrayList(); 70 $depts['0'] = array(0, '- ' . $AppUI->_('Select Unit') . ' -', -1); 71 } 72 73 // collect all the users for the department owner list 74 $q = new DBQuery; 75 $q->addTable('users', 'u'); 76 $q->addTable('contacts', 'con'); 77 $q->addQuery('user_id'); 78 $q->addQuery('CONCAT_WS(\' \',contact_first_name, contact_last_name)'); 79 $q->addOrder('contact_first_name'); 80 $q->addWhere('u.user_contact = con.contact_id'); 81 $q->addOrder('contact_last_name, contact_first_name'); 82 $owners = arrayMerge(array('0' => ''), $q->loadHashList()); 83 84 // setup the title block 85 $ttl = $company_id > 0 ? 'Edit Department' : 'Add Department'; 86 $titleBlock = new CTitleBlock($ttl, 'departments.png', $m, $m . '.' . $a); 87 $titleBlock->addCrumb('?m=departments', 'department list'); 88 $titleBlock->addCrumb('?m=companies', 'companies list'); 89 $titleBlock->addCrumb('?m=companies&a=view&company_id=' . $company_id, 'view this company'); 90 $titleBlock->show(); 91 ?> 92 <script language="javascript"> 93 function testURL( x ) { 94 var test = 'document.editFrm.dept_url.value'; 95 test = eval(test); 96 if (test.length > 6) { 97 newwin = window.open( 'http://' + test, 'newwin', '' ); 98 } 99 } 100 101 function submitIt() { 102 var form = document.editFrm; 103 if (form.dept_name.value.length < 2) { 104 alert( '<?php echo $AppUI->_('deptValidName', UI_OUTPUT_JS); ?>' ); 105 form.dept_name.focus(); 106 } else { 107 form.submit(); 108 } 109 } 110 </script> 111 112 <table cellspacing="0" cellpadding="4" border="0" width="100%" class="std"> 113 <form name="editFrm" action="?m=departments" method="post"> 114 <input type="hidden" name="dosql" value="do_dept_aed" /> 115 <input type="hidden" name="dept_id" value="<?php echo $dept_id; ?>" /> 116 <input type="hidden" name="dept_company" value="<?php echo $company_id; ?>" /> 117 118 <tr> 119 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Department Company'); ?>:</td> 120 <td><strong><?php echo $company_name; ?></strong></td> 121 </tr> 122 <tr> 123 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Department Name'); ?>:</td> 124 <td> 125 <input type="text" class="text" name="dept_name" value="<?php echo $drow['dept_name']; ?>" size="50" maxlength="255" /> 126 <span class="smallNorm">(<?php echo $AppUI->_('required'); ?>)</span> 127 </td> 128 </tr> 129 <tr> 130 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Email'); ?>:</td> 131 <td> 132 <input type="text" class="text" name="dept_email" value="<?php echo $drow['dept_email']; ?>" size="50" maxlength="255" /> 133 </td> 134 </tr> 135 <tr> 136 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Phone'); ?>:</td> 137 <td> 138 <input type="text" class="text" name="dept_phone" value="<?php echo $drow['dept_phone']; ?>" maxlength="30" /> 139 </td> 140 </tr> 141 <tr> 142 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Fax'); ?>:</td> 143 <td> 144 <input type="text" class="text" name="dept_fax" value="<?php echo $drow['dept_fax']; ?>" maxlength="30" /> 145 </td> 146 </tr> 147 <tr> 148 <td align="right"><?php echo $AppUI->_('Address'); ?>1:</td> 149 <td><input type="text" class="text" name="dept_address1" value="<?php echo $drow['dept_address1']; ?>" size="50" maxlength="255" /></td> 150 </tr> 151 <tr> 152 <td align="right"><?php echo $AppUI->_('Address'); ?>2:</td> 153 <td><input type="text" class="text" name="dept_address2" value="<?php echo $drow['dept_address2']; ?>" size="50" maxlength="255" /></td> 154 </tr> 155 <tr> 156 <td align="right"><?php echo $AppUI->_('City'); ?>:</td> 157 <td><input type="text" class="text" name="dept_city" value="<?php echo $drow['dept_city']; ?>" size="50" maxlength="50" /></td> 158 </tr> 159 <tr> 160 <td align="right"><?php echo $AppUI->_('State'); ?>:</td> 161 <td><input type="text" class="text" name="dept_state" value="<?php echo $drow['dept_state']; ?>" maxlength="50" /></td> 162 </tr> 163 <tr> 164 <td align="right"><?php echo $AppUI->_('Zip'); ?>:</td> 165 <td><input type="text" class="text" name="dept_zip" value="<?php echo $drow['dept_zip']; ?>" maxlength="15" /></td> 166 </tr> 167 <tr> 168 <td align="right"><?php echo $AppUI->_('Country'); ?>:</td> 169 <td> 170 <?php 171 echo arraySelect($countries, 'dept_country', 'size="1" class="text"', $drow['dept_country'] ? $drow['dept_country'] : 0); 172 ?> 173 </td> 174 </tr> 175 <tr> 176 <td align="right"><?php echo $AppUI->_('URL'); ?><a name="x"></a></td> 177 <td> 178 <input type="text" class="text" value="<?php echo $drow['dept_url']; ?>" name="dept_url" size="50" maxlength="255" /> 179 <a href="javascript: void(0);" onclick="testURL('dept_url')">[<?php echo $AppUI->_('test'); ?>]</a> 180 </td> 181 </tr> 182 183 <?php 184 if (count($depts)) { 185 ?> 186 <tr> 187 <td align="right" nowrap="nowrap"><?php echo $AppUI->_('Department Parent'); ?>:</td> 188 <td> 189 <?php 190 echo arraySelectTree($depts, 'dept_parent', 'class=text size=1', $drow['dept_parent']); 191 ?> 192 </td> 193 </tr> 194 <?php } else { 195 echo '<input type="hidden" name="dept_parent" value="0">'; 196 } 197 ?> 198 <tr> 199 <td align="right"><?php echo $AppUI->_('Owner'); ?>:</td> 200 <td> 201 <?php 202 echo arraySelect($owners, 'dept_owner', 'size="1" class="text"', $drow['dept_owner']); 203 ?> 204 </td> 205 </tr> 206 <tr> 207 <td align="right"><?php echo $AppUI->_('Type'); ?>:</td> 208 <td> 209 <?php 210 echo arraySelect($types, 'dept_type', 'size="1" class="text"', $drow['dept_type'], true); 211 ?> 212 </td> 213 </tr> 214 <tr> 215 <td align="right" valign="top" nowrap="nowrap"><?php echo $AppUI->_('Description'); ?>:</td> 216 <td align="left"> 217 <textarea cols="70" rows="10" class="textarea" name="dept_desc"><?php echo $drow['dept_desc']; ?></textarea> 218 </td> 219 </tr> 220 221 <tr> 222 <td> 223 <input type="button" value="<?php echo $AppUI->_('back'); ?>" class="button" onclick="javascript:history.back(-1);" /> 224 </td> 225 <td align="right"> 226 <input type="button" value="<?php echo $AppUI->_('submit'); ?>" class="button" onclick="submitIt()" /> 227 </td> 228 </tr> 229 </form> 230 </table> 231 <?php } ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 7 03:00:01 2009 | Cross-referenced by PHPXref 0.7 |