<? require_once("inc/header.php"); ?>
<?
$dat_dir = '../testimonials';

$org_type_lst = array(
       '0'   => "SELECT ONE",
       '15'  => "Church / Religious Organization",
       '3'   => "Corporation",
       '14'  => "Educational Institution",
       '5'   => "Government",
       '6'   => "Military",
       '13'  => "Non-Profit Organization",
       '10'  => "Other",
       '4'   => "Small Business"
);

$version_lst = array(
       '0'   => "SELECT ONE",
       '1'   => "1.36.x",
       '2'   => "1.38.x",
       '3'   => "2.0.x",
       '4'   => "2.2.x",
       '5'   => "SVN version"
);

$catalog_lst = array(
       '0'   => "SELECT ONE",
       '1'   => "MySQL",
       '2'   => "PostgreSQL",
       '3'   => "SqLite"
);

$org_industry_lst = array(
   '0'   => 'SELECT ONE',                               '25'  => 'Aerospace / Aeronautical',
   '11'  => 'Agriculture / Farming',                    '38'  => 'Architecture / Design',
   '44'  => 'Arts',                                     '5'   => 'ASP',
   '54'  => 'Banking',
   '42'  => 'Church / Religious Organization',          '45'  => 'Coaching',
   '10'  => 'Construction',                             '22'  => 'Consulting (General)',
   '21'  => 'Consulting (Information Technology)',      '31'  => 'Defense Industry',
   '51'  => 'Education / Training',                     '37'  => 'Energy Industry',
   '46'  => 'Engineering',                              '35'  => 'Entertainment (Film)',
   '34'  => 'Entertainment (Music)',                    '36'  => 'Entertainment (Other)',
   '47'  => 'Event Management / Conferences',           '7'   => 'Finance / Banking / Accounting',
   '12'  => 'Food Service Industry',                    '29'  => 'Government',
   '3'   => 'Healthcare / Medicine',                    '8'   => 'Higher Education',
   '6'   => 'Insurance',                                '4'   => 'Internet Service Provider',
   '2'   => 'K-12 Education',                           '48'  => 'Law Enforcement / Emergency Management',
   '14'  => 'Legal',                                    '24'  => 'Manufacturing (Computer Equipment)',
   '23'  => 'Manufacturing (General)',                  '53'  => 'Media (Publishing, Broadcasting, etc)',
   '30'  => 'Military',                                 '9'   => 'Mining',
   '18'  => 'Natural Resources / Environment',          '15'  => 'Pharmaceuticals',
   '49'  => 'Public Relations / Advertising',           '13'  => 'Real Estate',
   '41'  => 'Retail / Consumer Goods',                  '52'  => 'Sales / Marketing',
   '32'  => 'Scientific Research',                      '33'  => 'Sports / Recreation',
   '43'  => 'Technical College / Trade School',         '40'  => 'Telecommunications',
   '27'  => 'Transportation Industry (Air)',            '28'  => 'Transportation Industry (General)',
   '26'  => 'Transportation Industry (Marine)',         '50'  => 'Travel / Tourism / Lodging',
   '17'  => 'Travel Industry',                          '39'  => 'Utilities / Public Works',
   '16'  => 'Other'                             
);

$os_lst = array(
   '0'  =>  'SELECT ONE',                       '20' =>  'AIX',
   '21' =>  'FreeBSD',                          '14' =>  'HP-UX',
   '2'  =>  'Linux (Debian)',                   '27' =>  'Linux (Fedora)',
   '25' =>  'Linux (Gentoo)',                   '4'  =>  'Linux (Mandrake)',
   '5'  =>  'Linux (Other)',                    '1'  =>  'Linux (RedHat)',
   '26' =>  'Linux (Slackware)',                '3'  =>  'Linux (Suse)',
   '18' =>  'Mac OS X',                         '22' =>  'NetBSD',
   '23' =>  'OpenBSD',                          '24' =>  'Other',
   '13' =>  'Solaris',                          '15' =>  'Windows 2000',
   '16' =>  'Windows 2003',                     '17' =>  'Windows XP'
); 

$country_lst = array(
   '0'   =>  'SELECT ONE',              '1'   =>  'Afghanistan',
   '2'   =>  'Albania',                 '3'   =>  'Algeria',
   '4'   =>  'American Samoa',          '5'   =>  'Andorra',
   '6'   =>  'Angola',                  '7'   =>  'Anguilla',
   '8'   =>  'Antarctica',              '9'   =>  'Antigua and Barbuda',
   '10'  =>  'Argentina',               '11'  =>  'Armenia',
   '12'  =>  'Aruba',                   '13'  =>  'Australia',
   '14'  =>  'Austria',                 '15'  =>  'Azerbaijan',
   '16'  =>  'Bahamas',                 '17'  =>  'Bahrain',
   '18'  =>  'Bangladesh',              '19'  =>  'Barbados',
   '20'  =>  'Belarus',                 '21'  =>  'Belgium',
   '22'  =>  'Belize',                  '23'  =>  'Benin',
   '24'  =>  'Bermuda',                 '25'  =>  'Bhutan',
   '26'  =>  'Bolivia',                 '27'  =>  'Bosnia and Herzegovina',
   '28'  =>  'Botswana',                '29'  =>  'Bouvet Island',
   '30'  =>  'Brazil',                  '31'  =>  'Brunei Darussalam',
   '32'  =>  'Bulgaria',                '33'  =>  'Burkina Faso',
   '34'  =>  'Burundi',                 '35'  =>  'Cambodia',
   '36'  =>  'Cameroon',                '37'  =>  'Canada',
   '38'  =>  'Cape Verde',              '39'  =>  'Cayman Islands',
   '40'  =>  'Central African Republic','41'  =>  'Chad',
   '42'  =>  'Chile',                   '43'  =>  'China',
   '44'  =>  'Christmas Island',        '45'  =>  'Colombia',
   '46'  =>  'Comoros',                 '47'  =>  'Congo',
   '48'  =>  'Cook Islands',            '49'  =>  'Costa Rica',
   '54'  =>  "Ivory Coast",             '50'  =>  'Croatia',
   '51'  =>  'Cuba',                    '52'  =>  'Cyprus',
   '53'  =>  'Czech Republic',          '55'  =>  'Denmark',
   '56'  =>  'Djibouti',                '57'  =>  'Dominica',
   '58'  =>  'Dominican Republic',      '59'  =>  'East Timor',
   '60'  =>  'Ecuador',                 '61'  =>  'Egypt',
   '62'  =>  'El Salvador',             '63'  =>  'Equatorial Guinea',
   '64'  =>  'Eritrea',                 '65'  =>  'Estonia',
   '66'  =>  'Ethiopia',                '67'  =>  'Falkland Islands',
   '68'  =>  'Faroe Islands',           '69'  =>  'Fiji',
   '70'  =>  'Finland',                 '71'  =>  'France',
   '72'  =>  'French Guiana',           '73'  =>  'French Polynesia',
   '74'  =>  'Gabon',                   '75'  =>  'Gambia',
   '76'  =>  'Georgia',                 '77'  =>  'Germany',
   '78'  =>  'Ghana',                   '79'  =>  'Gibraltar',
   '80'  =>  'Greece',                  '81'  =>  'Greenland',
   '82'  =>  'Grenada',                 '83'  =>  'Guadeloupe',
   '84'  =>  'Guam',                    '85'  =>  'Guatemala',
   '86'  =>  'Guinea',                  '87'  =>  'Guinea-Bissau',
   '88'  =>  'Guyana',                  '89'  =>  'Haiti',
   '90'  =>  'Honduras',                '91'  =>  'Hong Kong',
   '92'  =>  'Hungary',                 '93'  =>  'Iceland',
   '94'  =>  'India',                   '95'  =>  'Indonesia',
   '96'  =>  'Iran',                    '97'  =>  'Iraq',
   '98'  =>  'Ireland',                 '99'  =>  'Israel',
   '100' =>  'Italy',                   '101' =>  'Jamaica',
   '102' =>  'Japan',                   '103' =>  'Jordan',
   '104' =>  'Kazakstan',               '105' =>  'Kenya',
   '106' =>  'Kiribati',                '107' =>  'Kuwait',
   '108' =>  'Kyrgystan',               '109' =>  'Lao',
   '110' =>  'Latvia',                  '111' =>  'Lebanon',
   '112' =>  'Lesotho',                 '113' =>  'Liberia',
   '232' =>  'Libya',                   '114' =>  'Liechtenstein',
   '115' =>  'Lithuania',               '116' =>  'Luxembourg',
   '117' =>  'Macau',                   '118' =>  'Macedonia (FYR)',
   '119' =>  'Madagascar',              '120' =>  'Malawi',
   '121' =>  'Malaysia',                '122' =>  'Maldives',
   '123' =>  'Mali',                    '124' =>  'Malta',
   '125' =>  'Marshall Islands',        '126' =>  'Martinique',
   '127' =>  'Mauritania',              '128' =>  'Mauritius',
   '129' =>  'Mayotte',                 '130' =>  'Mexico',
   '131' =>  'Micronesia',              '132' =>  'Moldova',
   '133' =>  'Monaco',                  '134' =>  'Mongolia',
   '135' =>  'Montserrat',              '136' =>  'Morocco',
   '137' =>  'Mozambique',              '138' =>  'Myanmar',
   '139' =>  'Namibia',                 '140' =>  'Nauru',
   '141' =>  'Nepal',                   '142' =>  'Netherlands',
   '143' =>  'Netherlands Antilles',    '144' =>  'Neutral Zone',
   '145' =>  'New Caledonia',           '146' =>  'New Zealand',
   '147' =>  'Nicaragua',               '148' =>  'Niger',
   '149' =>  'Nigeria',                 '150' =>  'Niue',
   '151' =>  'Norfolk Island',          '152' =>  'North Korea',
   '153' =>  'Northern Mariana Islands','154' =>  'Norway',
   '155' =>  'Oman',                    '156' =>  'Pakistan',
   '157' =>  'Palau',                   '158' =>  'Panama',
   '159' =>  'Papua New Guinea',        '160' =>  'Paraguay',
   '161' =>  'Peru',                    '162' =>  'Philippines',
   '163' =>  'Pitcairn',                '164' =>  'Poland',
   '165' =>  'Portugal',                '166' =>  'Puerto Rico',
   '167' =>  'Qatar',                   '168' =>  'Reunion',
   '169' =>  'Romania',                 '170' =>  'Russian Federation',
   '171' =>  'Rwanda',                  '172' =>  'Saint Helena',
   '173' =>  'Saint Kitts and Nevis',   '174' =>  'Saint Lucia',
   '175' =>  'Saint Pierre and Miquelon','231' =>  'Saint Vincent and the Grenadines',
   '176' =>  'Samoa',                   '177' =>  'San Marino',
   '178' =>  'Sao Tome and Principe',   '179' =>  'Saudi Arabia',
   '180' =>  'Senegal',                 '227' =>  'Serbia and Montenegro',
   '181' =>  'Seychelles',              '182' =>  'Sierra Leone',
   '183' =>  'Singapore',               '184' =>  'Slovakia',
   '185' =>  'Slovenia',                '186' =>  'Solomon Islands',
   '187' =>  'Somalia',                 '188' =>  'South Africa',
   '189' =>  'South Georgia',           '190' =>  'South Korea',
   '191' =>  'Spain',                   '192' =>  'Sri Lanka',
   '193' =>  'Sudan',                   '194' =>  'Suriname',
   '195' =>  'Swaziland',               '196' =>  'Sweden',
   '197' =>  'Switzerland',             '198' =>  'Syria',
   '199' =>  'Taiwan',                  '200' =>  'Tajikistan',
   '201' =>  'Tanzania',                '202' =>  'Thailand',
   '203' =>  'Togo',                    '204' =>  'Tokelau',
   '205' =>  'Tonga',                   '206' =>  'Trinidad and Tobago',
   '207' =>  'Tunisia',                 '208' =>  'Turkey',
   '209' =>  'Turkmenistan',            '210' =>  'Turks and Caicos Islands',
   '211' =>  'Tuvalu',                  '212' =>  'Uganda',
   '213' =>  'Ukraine',                 '214' =>  'United Arab Emirates',
   '215' =>  'United Kingdom',          '216' =>  'United States of America',
   '217' =>  'Uruguay',                 '218' =>  'Uzbekistan',
   '219' =>  'Vanuatu',                 '233' =>  'Vatican City',
   '220' =>  'Venezuela',               '221' =>  'Vietnam',
   '222' =>  'Virgin Islands (British)','223' =>  'Virgin Islands (U.S.)',
   '224' =>  'Wallis and Futuna Islands','225' =>  'Western Sahara',
   '226' =>  'Yemen',                   '228' =>  'Zaire',
   '229' =>  'Zambia',                  '230' =>  'Zimbabwe'
);

if ($_REQUEST['btnSubmit'] == 'Add' or $_REQUEST['btnSubmit'] == 'Modify')
{

?>
<table>
<tr>
        <td class="contentTopic">
                <? echo $_REQUEST['btnSubmit'] ?> Testimonial
        </td>
</tr>
<tr>
        <td class="content">

Want to let others know you're using Bacula? Submit a user profile!  Your
submission will be reviewed before being made publicly available.  We reserve
the right to edit your submission for spelling, grammar, etc. You will receive
an email when your profile has been approved for public viewing. Note that
while your contact name and email address are required (to verify
information if necessary), you can choose to have them not be published along
with your profile information.  
<br/><br/>
Fields marked with a * are required. Read the privacy notice below for
information about how this data will be used.

        </td>
</tr>

<tr>
        <td class="content">
<form enctype="multipart/form-data" method='post' action='?page=testimonial'>
<input type='hidden' name='page' value='testimonial'>
<table border='0' class='Content'>

<td class='ItemName'>
<font color='red'>*</font>Contact Name:</td>
<td class='ItemValue'><input type='text' class='ItemValue' id='contact_name' 
name='contact_name' size='30' maxlength='100' value=''></td>
<td class='ItemName'>Publish Contact Name?</td>
<td class='ItemValue'><select name='publish_contact' class='ItemValue'>
<option id='publish_contact_0'  value='0' SELECTED>No
<option id='publish_contact_1' value='1'>Yes
</select></td>
</tr>

<tr>
<td class='ItemName'><font color='red'>*</font>Email Address:</td>
<td class='ItemValue'><input type='text' class='ItemValue' name='email_address' 
id='email_address' size='30' maxlength='150' value=''></td>
<td class='ItemName'>Publish Email Address?</td><td class='ItemValue'>
<select name='publish_email' class='ItemValue'>
<option value='0' id='publish_email_0' SELECTED>No
<option value='1' id='publish_email_1' >Yes
</select></td>
</tr>

<tr><td class='ItemName'>Job Description/Title:</td>
<td class='ItemValue'>
<input type='text' name='title' id='title' size='30' maxlength='100' value=''></td></tr>
<tr><td colspan=4><br></td></tr>

<tr><td class='ItemName'><font color='red'>*</font>Organization Name:</td>
<td class='ItemValue'>
<input type='text' class='ItemValue' name='org_name' id='org_name' 
size='30' maxlength='100' value=''>
</td><td class='ItemName'>Publish Org Name?</td><td class='ItemValue'>
<select name='publish_orgname' class='ItemValue'>
<option value='0' id='publish_orgname_0' >No
<option value='1' id='publish_orgname_1' SELECTED>Yes
</select></td>
</tr>

<tr><td class='ItemName'><font color='red'>*</font>Organization Type:</td>
<td class='ItemValue' colspan='3'>
<select name='orgtype_id' class='ItemValue'>
<?

while(list ($key, $val) = each ($org_type_lst))
{
 echo "<option id='orgtype_id_$key' value='$key'>$val\n";
}

?>
</select>
</td></tr>

<tr><td class='ItemName'><font color='red'>*</font>Organization Industry/Function:</td>
<td class='ItemValue' colspan='3'>
<select name='orgindustry_id' class='ItemValue'>
<?

while(list ($key, $val) = each ($org_industry_lst))
{
 echo "<option id='orgindustry_id_$key' value='$key'>$val\n";
}

?>
</select>
</td></tr>

<tr><td class='ItemName'>
<font color='red'>*</font>Approx. Organization Size (# of Users):</td>
<td class='ItemValue'>
<input type='text' id='org_size' class='ItemValue' name='org_size' 
size='4' maxlength='6' value=''></td>
<td class='ItemName'>Publish Org Size?</td><td class='ItemValue'><select name='publish_orgsize' class='ItemValue'>
<option id='publish_orgsize_0' value='0' >No
<option id='publish_orgsize_1' value='1' SELECTED>Yes
</select></td>
</tr>
<tr>

<td class='ItemName'>Website URL:</td>
<td class='ItemValue'>
<input type='text' class='ItemValue' id='website' name='website' size='30'
 maxlength='150' value=''></td>
<td class='ItemName'>Publish Website?</td><td class='ItemValue'>
<select name='publish_website' class='ItemValue'>
<option id='publish_website_0' value='0' >No
<option id='publish_website_1' value='1' SELECTED>Yes
</select></td>
</tr>

<tr>
<td class='ItemName'>Organization Logo :</td>
<td class='ItemValue'>
<input type="file" name="org_logo" title="png, gif or jpeg file only please"/>
</td><td><i>max width 150px. png, gif or jpeg only</i></td>
</tr>

<tr><td class='ItemName'><font color='red'>*</font>Country:</td>
<td class='ItemValue'>
<select name='country_id' class='ItemValue'>
<?
while(list ($key, $val) = each ($country_lst))
{
 echo "<option id='country_id_$key' value='$key'>$val\n";
}

?>
</select>
</td></tr>

<tr><td colspan=4><br></td></tr>
<tr><td class='ItemName'><font color='red'>*</font>Bacula version:</td>
<td class='ItemValue'>
<select name='bacula_version' class='ItemValue'>
<?

while(list ($key, $val) = each ($version_lst))
{
 echo "<option id='bacula_version_$key' value='$key'>$val\n";
}

?>
</select>
</td></tr>
<tr><td class='ItemName'><font color='red'>*</font>Director OS:</td>
<td class='ItemValue'>
<select name='ostype_id' class='ItemValue'>
<?

while(list ($key, $val) = each ($os_lst))
{
 echo "<option id='ostype_id_$key' value='$key'>$val\n";
}

?>
</select>
</td></tr>
<tr><td class='ItemName'><font color='red'>*</font>Catalog DB:</td>
<td class='ItemValue'>
<select name='catalog_id' class='ItemValue'>
<?

while(list ($key, $val) = each ($catalog_lst))
{
 echo "<option id='catalog_id_$key' value='$key'>$val\n";
}

?>
</select>
</td></tr>
<tr>
<td class='ItemName'><font color='red'>*</font>Redundant/Failover Backup Setup?</td>
<td class='ItemValue'><select name='redundant_setup' class='ItemValue'>
<option value='0' id='redundant_setup_0' SELECTED>No
<option value='1' id='redundant_setup_1' >Yes
</select></td>
</tr>

<tr><td class='ItemName'><font color='red'>*</font>Number of Clients (Running bacula-fd):</td>
<td class='ItemValue'>
<input type='text' class='ItemValue' id='number_fd' name='number_fd' 
 size='5' maxlength='10' value=''></td>
</tr>

<tr><td class='ItemName'>
<font color='red'>*</font>Number of Storage Daemons (Running bacula-sd):</td>
<td class='ItemValue'>
<input type='text' class='ItemValue' id='number_sd' name='number_sd' size='5' 
 maxlength='10' value=''></td>
</tr>

<tr><td class='ItemName'><font color='red'>*</font>Total # of GB saved every month:</td>
<td class='ItemValue'><input type='text' class='ItemValue' name='month_gb' size='5' 
 id='month_gb' maxlength='10' value=''></td>
</tr>

<tr><td class='ItemName'><font color='red'>*</font>Number # of Files:</td>
<td class='ItemValue'><input type='text' class='ItemValue' name='number_files'
 id='number_files' title='select count(1) from File;' size='10' maxlength='15' value=''></td>
</tr>
<tr>

<td class='ItemName'>Need professional support:</td>
<td class='ItemValue'>
<select name='support' class='ItemValue'>
<option id='support_0' value='0' SELECTED>No
<option id='support_1' value='1'>Yes
</select></td>
</tr>

<tr><td colspan=4><br></td></tr>

<tr><td class='ItemName' valign='top'>Applicable Hardware and Network Information:</td>
<td class='ItemValue' colspan='3'>
<textarea name='hardware_comments' wrap='virtual' rows='4' id='hardware_comments'
 cols='60' class='ItemValue'>Loader Description:
Barcode Reader: Yes/No
Number of Storage Elements:
Number of Import/Export Elements:
--
Nics: 
...
</textarea>
</tr>

<tr><td class='ItemName' valign='top'>General Comments:</td>
<td class='ItemValue' colspan='3'>
<textarea name='comments' id='comments' wrap='virtual' rows='4' cols='60' 
 class='ItemValue'></textarea></tr>

<tr><td></td><td>
<?
 if ($_REQUEST['btnSubmit'] == 'Modify') {
  echo "<input type='text' title='testimonial id' id='id' name='id' class='ItemValue' value=''>";
  echo "<input type='submit' name='btnSubmit' class='ItemValue' value='Save'>";
  echo "<input type='submit' name='btnSubmit' class='ItemValue' onclick='confirm(\"Are you sure ?\");' value='Delete'><br>";
  echo "<input type='hidden' name='page' class='ItemValue' value='testimonial'><br>";

} else {  
  echo "<input type='submit' name='btnSubmit' class='ItemValue' value='Review Profile Submission'>";
}
?>

</td></tr>
</table>
</form>

</td>
</tr>
<tr>

        <td class="content">
        <h3 style="padding: 5px; border-bottom: 1px dotted #002244"> Privacy Notice </h3>

The following information is required, but you may choose to not have it
published for public viewing if you wish: contact name, email address,
organization name. We may use this information to verify the data you submit if
we find the need.
        </td>
</tr>


</table>
<?

}

if ($_REQUEST['btnSubmit'] == 'Modify') {
   $filename = get_file_from_id();

   if (!$filename) {
	return (0);
   }

   $formul = load_formul($filename);

   echo "<script type='text/javascript' language='JavaScript'>\n";
   $attribs = array('contact_name','email_address', 'org_name','title','website',
                    'month_gb','number_files', 'number_fd','number_sd',
                    'org_size','comments', 'hardware_comments', 'id');
   foreach ($attribs as $arr) {
           form_set_value($formul, $arr);
   }

   $attribs = array('publish_contact','publish_email', 'publish_orgname', 'orgtype_id', 
                    'orgindustry_id', 'publish_orgsize','publish_website', 'bacula_version',
                    'country_id','ostype_id', 'redundant_setup', 'catalog_id', 'support');
   foreach ($attribs as $arr) {
        form_set_selection($formul, $arr);
   }

   echo "</script>\n";

} elseif ($_REQUEST['btnSubmit'] == 'Review Profile Submission') {

        $form = get_formul();
        if (!$form) {
                echo "Sorry, something is missing, I cannot accept your submission";
        } else {
                $token = uniqid(md5(rand()), true);
                $filename = "$dat_dir/profile.$token";
        
                $form['filename'] = $filename;  
                $form['id'] = $token;
                save_formul($form);

                send_email($form['id'], $form['email_address']);
                echo "You can modify your profile <a href='?page=testimonial&btnSubmit=Modify&id=" . $form['id'] . "'>here</a> (keep this link as bookmark)<br><br>";
                print_formul($form);
        }

} elseif ($_REQUEST['btnSubmit'] == 'View') {
	
	$file = get_file_from_id();

	if ($file) {
	     print_formul_file($filename,true);
	}

} elseif ($_REQUEST['btnSubmit'] == 'Delete') {

	$filename = get_file_from_id();

	if (!$filename) {
	    return (0);
	}

        $form = load_formul($filename);
        
        if ($form['org_logo'] && file_exists($form['org_logo'])) {
            unlink($form['org_logo']);
        }
        if (file_exists($filename)) {
            unlink($filename);
            echo "Profile deleted";
        }

} elseif ($_REQUEST['btnSubmit'] == 'Accept' && is_admin()) {

	$filename = get_file_from_id();
        
	if (!$filename) {
	    return (0);
	}

        $form = load_formul($filename);

	$hide = $_REQUEST['hide'];

        if ($hide) {
                $form['visible']=0;
        } else {
		$form['visible']=1;
	}
        save_formul($form);
        echo $form['id'] . " is now " . ($hide?"un":"") . "visible";
        print_formul($form);

} elseif ($_REQUEST['btnSubmit'] == 'Save') {
	
	$filename = get_file_from_id();

	if (!$filename) {
	    return (0);
	}

        $form = get_formul();

        $form['filename'] = $filename;  
        $form['id'] = $_REQUEST['id'];  // id is clean
//      $form['visible'] = false;

        if (!$form['org_logo']) {
            $form_old = load_formul($filename);
            $form['org_logo'] = $form_old['org_logo'];
        }

        save_formul($form);

        echo "Your profile has been modified.<br>";
        print_formul($form);

} elseif ($_REQUEST['btnSubmit'] == 'Admin' && is_admin()) {


    $pass = $_REQUEST['passwd']; // passwd is clean
    $waiting = $_REQUEST['waiting'];
    
    if ($waiting) {
       print '<a href="?page=testimonial&btnSubmit=Admin&passwd=' . $pass . '"> View all</a><br>';
       print "<h1>View all waiting testimonials</h1>";
    } else {
       print '<a href="?page=testimonial&btnSubmit=Admin&waiting=1&passwd=' . $pass . '"> View Waiting</a><br>';
       print "<h1>View all testimonials</h1>";
    }

    if ($handle = opendir($dat_dir)) {
    /* Ceci est la facon correcte de traverser un dossier. */
            while (false !== ($file = readdir($handle))) {
                if (preg_match("/profile.[a-z0-9\.]+/", $file)) {
                     $form = load_formul("$dat_dir/$file") ;
			// on affiche ceux qui sont en attente ou bien tous
		     if (!$waiting || !$form['visible']) {
		        print_formul($form);
			if ($form['visible']) {
              		   print "<a href=\"?page=testimonial&btnSubmit=Accept&hide=1&passwd=" . $pass . "&id=" . $form['id'] . "\"> Hide </a> | \n";
			} else {
			   print "<a href=\"?page=testimonial&btnSubmit=Accept&passwd=" . $pass . "&id=" . $form['id'] . "\"> Accept </a> | \n";
			}
		        print "<a href=\"?page=testimonial&btnSubmit=Modify&id=" . $form['id'] . "\"> Modify </a> | \n";
              		print "<a href=\"?page=testimonial&btnSubmit=AdminExport&passwd=" . $pass . "&id=" . $form['id'] . "\"> Export </a><br><br>\n";

		     }
                }
            } 
            closedir($handle);
    } 

} elseif (!$_REQUEST['btnSubmit'] || $_REQUEST['btnSubmit'] == 'ViewAll') {

    $limit = $_REQUEST['limit'];
    $offset = $_REQUEST['offset'];

    $limit = is_int($limit)?$limit:10;
    $offset = is_int($offset)?$limit:0;

    $admin = is_admin();

    if ($limit > 20) { $limit = 20 ;}

    echo "<a href='?page=testimonial&btnSubmit=Add'>Add a testimonial</a><br><br>";

    if ($handle = opendir($dat_dir)) {
    /* Ceci est la facon correcte de traverser un dossier. */
            $i = 0 ;
            while (false !== ($file = readdir($handle))) {
                if (preg_match("/profile.[a-z0-9\.]+/", $file)) {
                    if ($i >= $offset && $i < ($offset + $limit)) {
                        $i += print_formul_file("$dat_dir/$file",$admin);
                    }

                    if ($i > ($offset + $limit)) {
                        break;
                    }
                }
            } 
            closedir($handle);
    }

} elseif ($_REQUEST['btnSubmit'] == 'AdminExport' && is_admin()) {

   $file = get_file_from_id();
   if (!$file) {
       return 0;
   }
   $form = load_formul($file);
   if ($form) {
	export_form($form);
   }
} else {
	print "Invalid btnSubmit<br>";
}

function export_form($formul)
{
        global $country_lst, $org_type_lst, $org_industry_lst, $os_lst, $catalog_lst;

        $attribs = array('contact_name','email_address', 'org_name','title','website',
			 'hardware_comments','comments',
			 'publish_contact','publish_email', 'publish_orgname','org_size','redundant_setup',
			 'date','visible', 'support',
			 'number_fd','number_sd','month_gb','number_files','publish_orgsize','publish_website');
	print "<pre>\n";
        foreach ($attribs as $arr) {
		print "$arr = " . $formul[$arr] . "\n";
        }

	print "orgtype = " . $org_type_lst[$formul['orgtype_id']] . "\n";
	print "orgindustry = " . $org_industry_lst[$formul['orgindustry_id']] . "\n";
	print "bacula_version = " . $version_lst[$formul['bacula_version']] . "\n";
	print "country = " . $country_lst[$formul['country_id']] . "\n";
	print "ostype = " . $os_lst[$formul['ostype_id']] . "\n";
	print "catalog = " . $catalog_lst[$formul['catalog_id']] . "\n";

	print "<pre>\n";
}

function get_file_from_id()
{
    global $dat_dir;
    $id = $_REQUEST['id'];

    if (!ereg('^[a-zA-Z0-9\.]+$',$id)) {
         return(0) ;
    }

    $filename="$dat_dir/profile.$id";

    if (!file_exists($filename)) {
         echo "Can't verify your id";
         return (0);
    }       

    return $filename;
}

function send_email($id, $email)
{
        // Your email address
        $from = 'kern@sibbald.com';
//        $from = 'eric@eb.homelinux.org';

        // The subject
        $subject = "[BACULA] New testimonial";

        // The message
        $message = "Hello, 
You can modify your new testimonial at http://www.bacula.org/?page=testimonial&btnSubmit=Modify&id=$id

Best regards.
";

        mail($email, $subject, $message, "From: Bacula WebMaster <$from>");
        mail($from, $subject, $message, "From: Bacula WebMaster <$from>");
        mail('eric@eb.homelinux.org', $subject, $message, "From: Bacula WebMaster <$from>");

        echo "The email has been sent for approval.<br/>";
}

function save_formul($form)
{
        $fp = fopen($form['filename'], 'w'); 
        fwrite($fp, serialize($form));
        fclose($fp);
}

function get_formul()
{
        global $dat_dir;
        $formul = array();
        $attribs = array('contact_name','email_address', 'org_name');
        foreach ($attribs as $arr) {
                if (!$_REQUEST[$arr]) {
                        echo "Can't get $arr<br/>";
                        return '';
                }
                $formul[$arr] = preg_replace('/[^a-zA-Z0-9!\.?\:\/,;_()@\n -]/', " ", $_REQUEST[$arr]);
        }

        $attribs = array('title','website','hardware_comments','comments');
        foreach ($attribs as $arr) {
                $formul[$arr] = preg_replace('/[^a-zA-Z0-9!\.?\:\/,;_()@ -]/', " ", $_REQUEST[$arr]);
        }

        $attribs = array('publish_contact','publish_email', 'publish_orgname', 'orgtype_id', 
                         'orgindustry_id','org_size', 'publish_orgsize','publish_website', 'bacula_version',
                         'country_id','ostype_id', 'redundant_setup','number_fd','number_sd','support',
                         'month_gb','number_files','catalog_id');
        foreach ($attribs as $arr) {
                if (preg_match("/^[0-9]+$/", $_REQUEST[$arr])) {
                        $formul[$arr] = $_REQUEST[$arr];
                }
        }

        $attribs = array('orgtype_id', 'orgindustry_id', 'org_size', 'country_id','bacula_version',
                         'catalog_id', 'ostype_id','number_fd','number_sd', 'month_gb','number_files');
        foreach ($attribs as $arr) {
                if (!$formul[$arr]) {
                        echo "Can't get $arr<br/>";
                        return '';
                }
        }

        if ($_FILES['org_logo']) {
                $token = uniqid(md5(rand()), true);
                $image = "upload/$token";

                if (preg_match("/(jpg|jpeg)$/i", $_FILES['org_logo']['name'])) {
                        $image = "$image.jpg";
                } elseif (preg_match("/png$/i", $_FILES['org_logo']['name'])) {
                        $image = "$image.png";
                } elseif (preg_match("/gif$/i", $_FILES['org_logo']['name'])) {
                        $image = "$image.gif";
                } else {
                        $image = '';
                }
                if ($image) {
                        $ret=move_uploaded_file($_FILES['org_logo']['tmp_name'], $image);
                        $formul['org_logo'] = $image;
                }
        }
        $formul['date'] = time();
        $formul['visible'] = false;

        return $formul;
}

function form_set_value($formul,$val)
{
 echo "document.getElementById('$val').value = '" . $formul[$val] . "';\n";
}

function form_set_selection($formul,$val)
{
 echo "document.getElementById('${val}_" . $formul[$val] . "').selected =true;\n";
}

// passwd file must exist in dat directory
function is_admin()
{
        global $dat_dir;
        $id = $_REQUEST['passwd'];

        if (!ereg('^[a-zA-Z]+$',$id)) {
            return(false) ;
        }
        
        if (file_exists("$dat_dir/$id")) {
            return true;
        } else {
            return false;
        }
}

function load_formul($filename)
{
        if (!file_exists($filename)) {
                return array();
        }

        if (!filesize($filename) || filesize($filename) > 10*1024*1024) {
            return undef;
        }
        $fp = fopen($filename, 'r');
        $contents = fread ($fp, filesize ($filename));
        fclose ($fp);

        $formul = unserialize($contents);
        if (!is_array($formul)) {
            return undef;
        }

        return $formul;
}

function print_formul_file($filename, $admin) {

        $formul = load_formul($filename);
        if (!$formul) {
                return 0;
        }
        
        if (!$admin) {
                if (!$formul['visible']) {
                        return 0;
                }
        } else {
		print "<a href=\"?page=testimonial&btnSubmit=Modify&id=" . $formul['id'] . "\">Modify</a><br>\n";
	}

	return print_formul($formul);
}

function print_formul($formul)
{
   global $country_lst, $org_type_lst, $org_industry_lst, $os_lst,$catalog_lst;

   ?>
   <table width="80%">
   <td>
   <b><? echo ($formul['publish_orgname'])?$formul['org_name']:'N/A' ?></b><br>
   <table>
   <tr><td> Location: </td><td><? $a = $formul['country_id'] ; echo $country_lst[$a] ?> </td></tr>
   <tr><td> Organization Type: </td><td><? echo $org_type_lst[$formul['orgtype_id']] ?> </td></tr>
   <tr><td> Industry/Function: </td><td><? echo $org_industry_lst[$formul['orgindustry_id']] ?> </td></tr>

   <? if ($formul['publish_orgsize']) { ?>
        <tr><td> Organisation Size: </td><td><? echo $formul['org_size'] ?> </td></tr>
   <? } ?>

   <? if ($formul['publish_website']) { ?>
        <tr><td> Website: </td><td><? echo $formul['website'] ?> </td></tr>
   <? } ?>

   <? if ($formul['number_fd'] > 1) { ?>
        <tr><td> Number of fd: </td><td><? echo $formul['number_fd'] ?> </td></tr>
   <? } ?>

   <? if ($formul['month_gb'] > 1) { ?>
        <tr><td> GB/Month: </td><td><? echo $formul['month_gb'] ?> </td></tr>
   <? } ?>

   <tr><td> Comments: </td><td width='450'><i><? echo $formul['comments'] ?> </i></td></tr>
   <? if ($formul['publish_contact']) { ?>
        <tr align='right'><td></td><td><i><? echo $formul['contact_name'] ?> </i></td></tr>
   <? } ?>
   </table>
   </td>
   <td>
   <? if ($formul['org_logo']) { ?>
        <a href="<? echo $formul['org_logo'] ?>" ><img width='150' src="<? echo $formul['org_logo'] ?>"></a>
   <? } ?>
   </td>
   </table>
<?
   return 1;
}

?>
<? require_once("inc/footer.php"); ?>
