Use a function to generate select options
This commit is contained in:
parent
938c5ef21c
commit
ef124c3e21
9 changed files with 81 additions and 36 deletions
|
@ -13,9 +13,7 @@
|
|||
<select id="category" name="categories[]" multiple="multiple" title="<?php echo $l->t("Select category") ?>">
|
||||
<?php
|
||||
if (!isset($_['categories'])) {$_['categories'] = array();}
|
||||
foreach($_['category_options'] as $category){
|
||||
echo '<option value="' . $category . '"' . (in_array($category, $_['categories']) ? ' selected="selected"' : '') . '>' . $category . '</option>';
|
||||
}
|
||||
echo html_select_options($_['category_options'], $_['categories'], array('combine'=>true));
|
||||
?>
|
||||
</select></td>
|
||||
<th width="75px"> <?php echo $l->t("Calendar");?>:</th>
|
||||
|
@ -23,9 +21,7 @@
|
|||
<select style="width:140px;" name="calendar">
|
||||
<?php
|
||||
if (!isset($_['calendar'])) {$_['calendar'] = false;}
|
||||
foreach($_['calendar_options'] as $calendar){
|
||||
echo '<option value="' . $calendar['id'] . '"' . ($_['calendar'] == $calendar['id'] ? ' selected="selected"' : '') . '>' . $calendar['displayname'] . '</option>';
|
||||
}
|
||||
echo html_select_options($_['calendar_options'], $_['calendar'], array('value'=>'id', 'label'=>'displayname'));
|
||||
?>
|
||||
</select></td>
|
||||
</tr>
|
||||
|
@ -66,9 +62,7 @@
|
|||
<select name="repeat" style="width:350px;">
|
||||
<?php
|
||||
if (isset($_['repeat_options'])) {
|
||||
foreach($_['repeat_options'] as $id => $label){
|
||||
echo '<option value="' . $id . '"' . ($_['repeat'] == $id ? ' selected="selected"' : '') . '>' . $label . '</option>';
|
||||
}
|
||||
echo html_select_options($_['repeat_options'], $_['repeat']);
|
||||
}
|
||||
?>
|
||||
</select></td>
|
||||
|
|
|
@ -51,10 +51,22 @@ if(is_null($vcard)){
|
|||
exit();
|
||||
}
|
||||
|
||||
$property_types = array(
|
||||
'ADR' => $l10n->t('Address'),
|
||||
'TEL' => $l10n->t('Telephone'),
|
||||
'EMAIL' => $l10n->t('Email'),
|
||||
'ORG' => $l10n->t('Organization'),
|
||||
);
|
||||
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
|
||||
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
|
||||
|
||||
$details = OC_Contacts_VCard::structureContact($vcard);
|
||||
$tmpl = new OC_Template('contacts','part.details');
|
||||
$tmpl->assign('details',$details);
|
||||
$tmpl->assign('id',$id);
|
||||
$tmpl->assign('property_types',$property_types);
|
||||
$tmpl->assign('adr_types',$adr_types);
|
||||
$tmpl->assign('phone_types',$phone_types);
|
||||
$page = $tmpl->fetchPage();
|
||||
|
||||
OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page )));
|
||||
|
|
|
@ -29,9 +29,14 @@ $l10n = new OC_L10N('contacts');
|
|||
OC_JSON::checkLoggedIn();
|
||||
OC_JSON::checkAppEnabled('contacts');
|
||||
|
||||
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
|
||||
$phone_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'TEL');
|
||||
|
||||
$addressbooks = OC_Contacts_Addressbook::all(OC_USER::getUser());
|
||||
$tmpl = new OC_Template('contacts','part.addcardform');
|
||||
$tmpl->assign('addressbooks',$addressbooks);
|
||||
$tmpl->assign('adr_types',$adr_types);
|
||||
$tmpl->assign('phone_types',$phone_types);
|
||||
$page = $tmpl->fetchPage();
|
||||
|
||||
OC_JSON::success(array('data' => array( 'page' => $page )));
|
||||
|
|
|
@ -61,11 +61,13 @@ if(is_null($line)){
|
|||
exit();
|
||||
}
|
||||
|
||||
$adr_types = OC_Contacts_VCard::getTypesOfProperty($l10n, 'ADR');
|
||||
|
||||
$tmpl = new OC_Template('contacts','part.setpropertyform');
|
||||
$tmpl->assign('id',$id);
|
||||
$tmpl->assign('checksum',$checksum);
|
||||
$tmpl->assign('property',OC_Contacts_VCard::structureProperty($vcard->children[$line]));
|
||||
$tmpl->assign('adr_types',$adr_types);
|
||||
$page = $tmpl->fetchPage();
|
||||
|
||||
OC_JSON::success(array('data' => array( 'page' => $page )));
|
||||
|
|
|
@ -372,4 +372,24 @@ class OC_Contacts_VCard{
|
|||
return null;
|
||||
}
|
||||
}
|
||||
public static function getTypesOfProperty($l, $prop){
|
||||
switch($prop){
|
||||
case 'ADR':
|
||||
return array(
|
||||
'WORK' => $l->t('Work'),
|
||||
'HOME' => $l->t('Home'),
|
||||
);
|
||||
case 'TEL':
|
||||
return array(
|
||||
'HOME' => $l->t('Home'),
|
||||
'CELL' => $l->t('Mobile'),
|
||||
'WORK' => $l->t('Work'),
|
||||
'TEXT' => $l->t('Text'),
|
||||
'VOICE' => $l->t('Voice'),
|
||||
'FAX' => $l->t('Fax'),
|
||||
'VIDEO' => $l->t('Video'),
|
||||
'PAGER' => $l->t('Pager'),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
<li class="input stringish">
|
||||
<label class="label" for="id"><?php echo $l->t('Group'); ?></label>
|
||||
<select name="id" size="1">
|
||||
<?php foreach($_['addressbooks'] as $addressbook): ?>
|
||||
<option value="<?php echo $addressbook['id']; ?>"><?php echo $addressbook['displayname']; ?></option>
|
||||
<?php endforeach; ?>
|
||||
<?php echo html_select_options($_['addressbooks'], null, array('value'=>'id', 'label'=>'displayname')); ?>
|
||||
</select>
|
||||
</li>
|
||||
</ol>
|
||||
|
@ -46,14 +44,7 @@
|
|||
<li class="fragment">
|
||||
<label for="tel_type"><?php echo $l->t('Type'); ?></label>
|
||||
<select id="TEL" name="parameters[TEL][TYPE]" size="1">
|
||||
<option value="home"><?php echo $l->t('Home'); ?></option>
|
||||
<option value="cell" selected="selected"><?php echo $l->t('Mobile'); ?></option>
|
||||
<option value="work"><?php echo $l->t('Work'); ?></option>
|
||||
<option value="text"><?php echo $l->t('Text'); ?></option>
|
||||
<option value="voice"><?php echo $l->t('Voice'); ?></option>
|
||||
<option value="fax"><?php echo $l->t('Fax'); ?></option>
|
||||
<option value="video"><?php echo $l->t('Video'); ?></option>
|
||||
<option value="pager"><?php echo $l->t('Pager'); ?></option>
|
||||
<?php echo html_select_options($_['phone_types'], 'CELL') ?>
|
||||
</select>
|
||||
</li>
|
||||
</ol>
|
||||
|
@ -67,8 +58,7 @@
|
|||
<li class="input">
|
||||
<label class="label" for="adr_type"><?php echo $l->t('Type'); ?></label>
|
||||
<select id="adr_type" name="parameters[ADR][TYPE]" size="1">
|
||||
<option value="work"><?php echo $l->t('Work'); ?></option>
|
||||
<option value="home" selected="selected"><?php echo $l->t('Home'); ?></option>
|
||||
<?php echo html_select_options($_['adr_types'], 'HOME') ?>
|
||||
</select>
|
||||
</li>
|
||||
<li class="input stringish">
|
||||
|
|
|
@ -27,10 +27,7 @@
|
|||
<input type="hidden" name="id" value="<?php echo $_['id']; ?>">
|
||||
<p class="contacts_property_name">
|
||||
<select name="name" size="1">
|
||||
<option value="ADR"><?php echo $l->t('Address'); ?></option>
|
||||
<option value="TEL"><?php echo $l->t('Telephone'); ?></option>
|
||||
<option value="EMAIL" selected="selected"><?php echo $l->t('Email'); ?></option>
|
||||
<option value="ORG"><?php echo $l->t('Organization'); ?></option>
|
||||
<?php echo html_select_options($_['property_types'], 'EMAIL') ?>
|
||||
</select>
|
||||
</p>
|
||||
<p class="contacts_property_data" id="contacts_generic">
|
||||
|
@ -44,8 +41,7 @@
|
|||
<li>
|
||||
<label for="adr_type"><?php echo $l->t('Type'); ?></label>
|
||||
<select id="adr_type" name="parameters[TYPE]" size="1">
|
||||
<option value="work"><?php echo $l->t('Work'); ?></option>
|
||||
<option value="home" selected="selected"><?php echo $l->t('Home'); ?></option>
|
||||
<?php echo html_select_options($_['adr_types'], 'HOME') ?>
|
||||
</select>
|
||||
</li>
|
||||
<li>
|
||||
|
@ -80,14 +76,7 @@
|
|||
<p class="contacts_property_data" id="contacts_phonepart">
|
||||
<input type="text" name="value" value="">
|
||||
<select name="parameters[TYPE]" size="1">
|
||||
<option value="home"><?php echo $l->t('Home'); ?></option>
|
||||
<option value="cell" selected="selected"><?php echo $l->t('Mobile'); ?></option>
|
||||
<option value="work"><?php echo $l->t('Work'); ?></option>
|
||||
<option value="text"><?php echo $l->t('Text'); ?></option>
|
||||
<option value="voice"><?php echo $l->t('Voice'); ?></option>
|
||||
<option value="fax"><?php echo $l->t('Fax'); ?></option>
|
||||
<option value="video"><?php echo $l->t('Video'); ?></option>
|
||||
<option value="pager"><?php echo $l->t('Pager'); ?></option>
|
||||
<?php echo html_select_options($_['phone_types'], 'CELL') ?>
|
||||
</select>
|
||||
</p>
|
||||
<p class="contacts_property_data" id="contacts_generic">
|
||||
|
|
|
@ -5,6 +5,12 @@
|
|||
<?php if($_['property']['name']=='ADR'): ?>
|
||||
<p class="contacts_property_name"><label for="adr_pobox"><?php echo $l->t('Address'); ?></label></p>
|
||||
<ol class="contacts_property_data" id="contacts_addresspart">
|
||||
<li class="input">
|
||||
<label class="label" for="adr_type"><?php echo $l->t('Type'); ?></label>
|
||||
<select id="adr_type" name="parameters[TYPE]" size="1">
|
||||
<?php echo html_select_options($_['adr_types'], strtoupper($_['property']['parameters']['TYPE'])) ?>
|
||||
</select>
|
||||
</li>
|
||||
<li>
|
||||
<label for="adr_pobox"><?php echo $l->t('PO Box'); ?></label>
|
||||
<input id="adr_pobox" type="text" name="value[0]" value="<?php echo $_['property']['value'][0] ?>">
|
||||
|
|
|
@ -98,6 +98,33 @@ function relative_modified_date($timestamp) {
|
|||
else { return $l->t('years ago'); }
|
||||
}
|
||||
|
||||
function html_select_options($options, $selected, $params=array()) {
|
||||
if (!is_array($selected)){
|
||||
$selected=array($selected);
|
||||
}
|
||||
if (isset($params['combine']) && $params['combine']){
|
||||
$options = array_combine($options, $options);
|
||||
}
|
||||
$value_name = $label_name = false;
|
||||
if (isset($params['value'])){
|
||||
$value_name = $params['value'];
|
||||
}
|
||||
if (isset($params['label'])){
|
||||
$label_name = $params['label'];
|
||||
}
|
||||
$html = '';
|
||||
foreach($options as $value => $label){
|
||||
if ($value_name && is_array($label)){
|
||||
$value = $label[$value_name];
|
||||
}
|
||||
if ($label_name && is_array($label)){
|
||||
$label = $label[$label_name];
|
||||
}
|
||||
$select = in_array($value, $selected) ? ' selected="selected"' : '';
|
||||
$html .= '<option value="' . $value . '"' . $select . '>' . $label . '</option>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides the templates for owncloud.
|
||||
|
|
Loading…
Reference in a new issue