1<?php 2if(!defined('OSTADMININC') || !$thisstaff || !$thisstaff->isAdmin()) die('Access Denied'); 3$info = $members = $qs = array(); 4if ($team && $_REQUEST['a']!='add') { 5 //Editing Team 6 $title=__('Update Team'); 7 $action='update'; 8 $submit_text=__('Save Changes'); 9 $trans['name'] = $team->getTranslateTag('name'); 10 $members = $team->getMembers(); 11 $qs += array('id' => $team->getId()); 12} else { 13 $title=__('Add New Team'); 14 $action='create'; 15 $submit_text=__('Create Team'); 16 if (!$team) { 17 $team = Team::create(array( 18 'flags' => Team::FLAG_ENABLED, 19 )); 20 } 21 $qs += array('a' => $_REQUEST['a']); 22} 23 24$info = $team->getInfo(); 25?> 26<form action="teams.php?<?php echo Http::build_query($qs); ?>" method="post" class="save"> 27 <?php csrf_token(); ?> 28 <input type="hidden" name="do" value="<?php echo $action; ?>"> 29 <input type="hidden" name="a" value="<?php echo Format::htmlchars($_REQUEST['a']); ?>"> 30 <input type="hidden" name="id" value="<?php echo $team->getId(); ?>"> 31 <h2><?php echo $title; ?> 32 <?php if (isset($team->name)) { ?><small> 33 — <?php echo $team->getName(); ?></small> 34 <?php } ?> 35 <i class="help-tip icon-question-sign" href="#teams"></i> 36</h2> 37<br> 38<ul class="clean tabs"> 39 <li class="active"><a href="#team"> 40 <i class="icon-file"></i> <?php echo __('Team'); ?></a></li> 41 <li><a href="#members"> 42 <i class="icon-group"></i> <?php echo __('Members'); ?></a></li> 43</ul> 44 45<div id="team" class="tab_content"> 46 <table class="form_table" width="940" border="0" cellspacing="0" cellpadding="2"> 47 <thead> 48 <tr> 49 <th colspan="2"> 50 <em><strong><?php echo __('Team Information'); ?></strong>:</em> 51 </th> 52 </tr> 53 </thead> 54 <tbody> 55 <tr> 56 <td width="180" class="required"> 57 <?php echo __('Name');?>: 58 </td> 59 <td> 60 <input type="text" size="30" name="name" value="<?php echo Format::htmlchars($team->name); ?>" 61 autofocus data-translate-tag="<?php echo $trans['name']; ?>"/> 62 <span class="error">* <?php echo $errors['name']; ?></span> 63 </td> 64 </tr> 65 <tr> 66 <td width="180" class="required"> 67 <?php echo __('Status');?>: 68 </td> 69 <td> 70 <span> 71 <input type="radio" name="isenabled" value="1" <?php echo $team->isEnabled()?'checked="checked"':''; ?>><strong><?php echo __('Active');?></strong> 72 73 <input type="radio" name="isenabled" value="0" <?php echo !$team->isEnabled()?'checked="checked"':''; ?>><?php echo __('Disabled');?> 74 <span class="error">* </span> 75 <i class="help-tip icon-question-sign" href="#status"></i> 76 </span> 77 </td> 78 </tr> 79 <tr> 80 <td width="180"> 81 <?php echo __('Team Lead');?>: 82 </td> 83 <td> 84 <span> 85 <select id="team-lead-select" name="lead_id" data-quick-add="staff"> 86 <option value="0">— <?php echo __('None');?> —</option> 87<?php if ($members) { 88 foreach($members as $k=>$staff){ 89 $selected=($team->lead_id && $staff->getId()==$team->lead_id)?'selected="selected"':''; 90 echo sprintf('<option value="%d" %s>%s</option>',$staff->getId(),$selected,$staff->getName()); 91 } 92 } ?> 93 <option value="0" data-quick-add>— <?php echo __('Add New');?> —</option> 94 </select> 95 <span class="error"><?php echo $errors['lead_id']; ?></span> 96 <i class="help-tip icon-question-sign" href="#lead"></i> 97 </span> 98 </td> 99 </tr> 100 <tr> 101 <td width="180"> 102 <?php echo __('Assignment Alert');?>: 103 </td> 104 <td> 105 <input type="checkbox" name="noalerts" value="1" <?php echo !$team->alertsEnabled()?'checked="checked"':''; ?> > 106 <?php echo sprintf(__('<strong>Disable</strong> for %s'), __('this team')); ?> 107 <i class="help-tip icon-question-sign" href="#assignment_alert"></i> 108 </td> 109 </tr> 110 <tr> 111 <th colspan="2"> 112 <em><strong><?php echo __('Admin Notes');?></strong>: <?php echo __('Internal notes viewable by all admins.');?> </em> 113 </th> 114 </tr> 115 <tr> 116 <td colspan=2> 117 <textarea class="richtext no-bar" name="notes" cols="21" 118 rows="8" style="width: 80%;"><?php echo Format::htmlchars($team->notes); ?></textarea> 119 </td> 120 </tr> 121 </tbody> 122</table> 123</div> 124 125<?php 126$agents = Staff::getStaffMembers(); 127foreach ($members as $m) 128 unset($agents[$m->staff_id]); 129?> 130 131<div id="members" class="tab_content" style="display:none"> 132 <table class="two-column table" width="100%"> 133 <tbody> 134 <tr class="header"> 135 <td colspan="2"> 136 <?php echo __('Team Members'); ?> 137 <div><small> 138 <?php echo sprintf(__('Agents who are members of %s'), __('this team')); ?> 139 <i class="help-tip icon-question-sign" href="#members"></i> 140 </small></div> 141 </td> 142 </tr> 143 <tr id="add_member"> 144 <td colspan="2"> 145 <i class="icon-plus-sign"></i> 146 <select id="add_access" data-quick-add="staff"> 147 <option value="0">— <?php echo __('Select Agent');?> —</option> 148 <?php 149 foreach ($agents as $id=>$name) { 150 echo sprintf('<option value="%d">%s</option>',$id,Format::htmlchars($name)); 151 } 152 ?> 153 <option value="0" data-quick-add>— <?php echo __('Add New');?> —</option> 154 </select> 155 <button type="button" class="action-button"> 156 <?php echo __('Add'); ?> 157 </button> 158 </td> 159 </tr> 160 </tbody> 161 <tbody> 162 <tr id="member_template" class="hidden"> 163 <td> 164 <input type="hidden" data-name="members[]" value="" /> 165 </td> 166 <td> 167 <label> 168 <input type="checkbox" data-name="member_alerts" value="1" /> 169 <?php echo __('Alerts'); ?> 170 </label> 171 <a href="#" class="pull-right drop-membership" title="<?php echo __('Delete'); 172 ?>"><i class="icon-trash"></i></a> 173 </td> 174 </tr> 175 </tbody> 176 </table> 177</div> 178 179<p style="text-align:center"> 180 <input type="submit" name="submit" value="<?php echo $submit_text; ?>"> 181 <input type="reset" name="reset" value="<?php echo __('Reset');?>"> 182 <input type="button" name="cancel" value="<?php echo __('Cancel');?>" onclick='window.location.href="?"'> 183</p> 184</form> 185 186<script type="text/javascript"> 187var addMember = function(staffid, name, alerts, error) { 188 if (!staffid) return; 189 var copy = $('#member_template').clone(); 190 191 copy.find('[data-name=members\\[\\]]') 192 .attr('name', 'members[]') 193 .val(staffid); 194 copy.find('[data-name^=member_alerts]') 195 .attr('name', 'member_alerts['+staffid+']') 196 .prop('checked', alerts); 197 copy.find('td:first').append(document.createTextNode(name)); 198 copy.attr('id', '').show().insertBefore($('#add_member')); 199 copy.removeClass('hidden') 200 if (error) 201 $('<div class="error">').text(error).appendTo(copy.find('td:last')); 202}; 203 204$('#add_member').find('button').on('click', function() { 205 var selected = $('#add_access').find(':selected'), 206 id = parseInt(selected.val()); 207 if (!id) 208 return; 209 addMember(id, selected.text(), true); 210 if ($('#team-lead-select option[value='+id+']').length === 0) { 211 $('#team-lead-select').find('option[data-quick-add]') 212 .before( 213 $('<option>').val(selected.val()).text(selected.text()) 214 ); 215 } 216 selected.remove(); 217 return false; 218}); 219 220$(document).on('click', 'a.drop-membership', function() { 221 var tr = $(this).closest('tr'), 222 id = tr.find('input[name^=members][type=hidden]').val(); 223 $('#add_access').append( 224 $('<option>') 225 .attr('value', id) 226 .text(tr.find('td:first').text()) 227 ); 228 $('#team-lead-select option[value='+id+']').remove(); 229 tr.fadeOut(function() { $(this).remove(); }); 230 return false; 231}); 232 233<?php 234if ($team && $team->members) { 235 foreach ($team->members->sort(function($a) { return $a->staff->getName(); }) as $member) { 236 echo sprintf('addMember(%d, %s, %d, %s);', 237 $member->staff_id, 238 JsonDataEncoder::encode((string) $member->staff->getName()), 239 $member->isAlertsEnabled(), 240 JsonDataEncoder::encode($errors['members'][$member->staff_id]) 241 ); 242 } 243} 244?> 245</script> 246