cvs: php-hosts-web / host-services-edit.php /clients host-services-edit.php

From: Date: Thu, 25 Apr 2002 03:31:21 +0000
Subject: cvs: php-hosts-web / host-services-edit.php /clients host-services-edit.php
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-9851@lists.php.net to get a copy of this message
jimw Wed Apr 24 23:31:21 2002 EDT Added files: /php-hosts-web host-services-edit.php Removed files: /php-hosts-web/clients host-services-edit.php Log: service editing

Index: php-hosts-web/host-services-edit.php +++ php-hosts-web/host-services-edit.php <?php require 'shared.inc'; $hostid = (int)$hostid; /* just bounce requests with no hostid. */ if (!$hostid) { header("Location: /"); exit; } $user = verify_host_login(); if ($user != $hostid && !verify_staff_login()) { commonHeader("Not Authorized"); ?> <div class="errors">You are either not logged in as a staff member (someone with a PHP CVS account) or as the contact for this hosting company. Please <a href="login.php">log in</a> here to be able to delete the information about this hosting company.</div> <?php commonFooter(); exit; } /* get information about the host */ $query = "SELECT * FROM hosts WHERE HostId = $hostid"; $res = mysql_query($query) or die("query failed: ".mysql_query()); $host = mysql_fetch_assoc($res); $errors = array(); if ($mode == "edit") { $querys = array(); while (list(,$serviceid)=each($sid)) { $servicetype = $stype[$serviceid]; $servicename = $sname[$serviceid]; $temp = "value_" . $serviceid; $value = $$temp; switch ($servicetype) { case "single": if ($value != -1) { $querys[] = "insert into host_services (HostID,ServiceID,OptionID) values ($hostid,$serviceid,$value)"; } break; case "multiple": if ($value) { while (list(,$v)=each($value)) { if ($v) { $querys[] = "insert into host_services (HostID,ServiceID,OptionID) values ($hostid,$serviceid,$v)"; } } } break; case "multiplev": if ($value) { while (list($k,$v)=each($value)) { $temp = "valuev_" . $serviceid; $value2 = ${$temp}[$k]; if ($k) { $querys[] = "insert into host_services (HostID,ServiceID,OptionID,OptionValue) values ($hostid,$serviceid,$k,'$value2')"; } } } break; case "boolean": if ($value!=-1) { $querys[] = "insert into host_services (HostID,ServiceID,OptionID) values ($hostid,$serviceid,$value)"; } break; case "booleanv": if ($value!=-1) { $temp = "valuev_" . $serviceid; $value2 = $$temp; $querys[] = "insert into host_services (HostID,ServiceID,OptionID,OptionValue) values ($hostid,$serviceid,$value,'$value2')"; } break; case "text": if ($value) { $querys[] = "insert into host_services (HostID,ServiceID,OptionValue) values ($hostid,$serviceid,'$value')"; } break; case "number": if ($value) { $querys[] = "insert into host_services (HostID,ServiceID,OptionValue) values ($hostid,$serviceid,'$value')"; } break; case "free": if ($value) { $querys[] = "insert into host_services (HostID,ServiceID,OptionValueEx) values ($hostid,$serviceid,'$value')"; } break; } } @reset($querys); if (!$errors) { $query = "delete from host_services where HostID=$hostid"; $q1 = mysql_query($query) or die ("\"$query\" is a bad query."); if ($querys) { while (list(,$query)=each($querys)) { if (!@mysql_query($query)) { $errors[] = "Query failed: ".mysql_error(). " <code>$query</code>"; } } } if (!$errors) { header("Location: showinfo.php?hostid=$hostid&edit=1"); exit; } $errors[] = "Something went wrong when updating the database."; } } commonHeader("Edit Services for ".htmlentities($host['HostName'])); if ($errors) display_errors($errors); ?> <form method="post" action="<?php echo $PHP_SELF;?>"> <table border="0" cellspacing="0" cellpadding="5"> <?php $query = "SELECT ServiceName,ServiceType,OptionName,OptionValue,OptionValueEx," . "services.ServiceId,options.OptionId," . "host_services.OptionId AS opt,host_services.HostId" . " FROM services" . " LEFT JOIN options" . " ON services.ServiceID = options.ServiceID" . " LEFT JOIN host_services" . " ON host_services.HostID = $hostid" . " AND services.ServiceID = host_services.ServiceID" . " AND (host_services.OptionId <= 1" # handle booleans . " OR host_services.OptionID = options.OptionID)" . " ORDER BY services.Sort,options.Sort"; $res = mysql_query($query) or die("query failed: ".mysql_error()."<br />".htmlentities($query)); $service = mysql_fetch_assoc($res); $last = ""; # this keeps track of which service we're doing $closelast = ""; # this is used to close the services options after listing them do {?> <tr valign="top" class="<?php echo $i++ % 2 ? 'odd' : 'even';?>"> <th align="right"><?php echo $service['ServiceName'];?>:</th> <td><?php if ($service['ServiceName'] != $last) { $last = $service['ServiceName']; echo "<input type=\"hidden\" name=\"sid[]\" value=\"$service[ServiceId]\" />"; echo "<input type=\"hidden\" name=\"stype[$service[ServiceId]]\" value=\"$service[ServiceType]\" />"; echo "<input type=\"hidden\" name=\"sname[$service[ServiceId]]\" value=\"$service[ServiceName]\" />"; /* start the multi-optioned types */ switch ($service['ServiceType']) { case 'single': echo "<select name=\"value_$service[ServiceId]\">"; echo '<option value="-1">---</option>'; $closelast = '</select>'; break; case 'multiple': echo "<select name=\"value_$service[ServiceId][]\" multiple=\"multiple\">"; $closelast = '</select>'; break; } } do { switch ($service['ServiceType']) { case 'single': # TODO: preserve values correctly echo '<option value="', $service['OptionId'], '"', ($service['HostId'] ? ' selected="selected"' : ''), '>', $service['OptionName'], '</option>'; break; case 'multiple': # TODO: preserve values correctly echo '<option value="', $service['OptionId'], '"', ($service['HostId'] ? ' selected="selected"' : ''), '>', $service['OptionName'], '</option>'; break; case 'multiplev': # TODO: preserve values correctly echo '<input type="checkbox"', ' name="value_', $service['ServiceId'], '[', $service['OptionId'], ']"', ' id="value_', $service['ServiceId'], '[', $service['OptionId'], ']"', ($service['opt'] ? ' checked="checked"' : ''), ' /><label for="value_',$service['ServiceId'], '[', $service['OptionId'], ']">', $service['OptionName'], '</label>'; echo ' - version: '; echo '<input type="text" name="valuev_', $service['ServiceId'], '[', $service['OptionId'], ']" size="10" value="', oneof(clean(${"valuev_".$service['ServiceId']}[$service['OptionId']]),htmlentities($service['OptionValue'])), '" /><br />'; break; case 'boolean': # TODO: preserve values correctly echo '<select name="value_', $service['ServiceId'], '"><option value="-1">---</option>', '<option value="0"',($service['opt'] === '0' ? ' selected="selected"' : ''), '>No</option>', '<option value="1"',($service['opt'] === '1' ? ' selected="selected"' : ''), '>Yes</option>', '</select>'; break; case 'booleanv': # TODO: preserve values correctly echo '<select name="value_', $service['ServiceId'], '"><option value="-1">---</option>', '<option value="0"',($service['opt'] === '0' ? ' selected="selected"' : ''), '>No</option>', '<option value="1"',($service['opt'] === '1' ? ' selected="selected"' : ''), '>Yes</option>', '</select>'; echo ' If yes, version: '; echo '<input type="text" name="valuev_', $service['ServiceId'], '" size="10" value="', oneof(clean(${"valuev_".$service['ServiceId']}),htmlentities($service['OptionValue'])), '" />'; break; case 'text': case 'number': echo '<input type="text" name="value_', $service['ServiceId'], '" size="50" value="', oneof(clean(${"value_".$service['ServiceId']}),htmlentities($service['OptionValue'])), '" />'; break; case 'free': echo '<textarea name="value_', $service['ServiceId'], '" rows="5" cols="40">', oneof(clean(${"value_".$service['ServiceId']}),htmlentities($service['OptionValueEx']),htmlentities($service['OptionValue'])), '</textarea>'; break; } $service = mysql_fetch_assoc($res); } while ($service['ServiceName'] == $last); if ($closelast) echo $closelist; $closelast = ""; ?> </td> </tr> <?php } while ($service); ?> <tr> <td colspan="2" align="center"> <input type="hidden" name="mode" value="edit" /> <input type="hidden" name="hostid" value="<?php echo $hostid;?>" /> <input type="submit" value="Save Changes" /> </td> </tr> </table> </form> <?php commonFooter(); ?>
« previous php.mirrors (#9851) next »