[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.8

Professional PHP Programmer help needed for this one."I tried to give 600 pts for this one"

Asked by ricbax in PHP Scripting Language

Tags: php, base64_decode, header

Ok I am doing a project for a company, and I contracted a programmer to do a mailing list application for us, and it also includes an administration section. Unfortunately they mislead us and gave us an application that does not fully work. I am not the greatest when it comes to php programming, but I have an idea how some of this application works. The fact that the code is not commented also makes it difficult.

After going through the code that I am about to mention below, I have found that  the following 2 files "management.php" & "required.inc" does all of main communication with the MySQL database, the reading,writing and updating. They will allow updates and reading of records, but will not allow writing of new records. This file also should format the records with alternating row colors, however the alternating row code does not work and all style for the records table is lost.

This is the code for "management.php"

<?php
                session_start();
      include_once('required.inc');
      authenticate();
      reset($_GET);reset($_POST);
               
                HTML CODE HERE

      $action = $_GET['action'];
      if($action!='editing'){echo '<div align="left"><img src="../images/adminpanel.gif" alt="Join Mailing List Header" width="400" height="60" border="0"></div>';}
      $db_name='mailinglist_db';
      $tb_name='promo_list';
      if($_SESSION['authorized']){
                  connect_to_database('localhost','username','password');
                  use_database($db_name);
                  $table_fields = get_table_fields($db_name,$tb_name);
                  array_pop($table_fields);array_pop($table_fields);
                  $where = "join_list='TRUE'";
                  if($action=='delete'){remove_record($tb_name,('record = '.$_GET['record']));}
                        else if($action=='editing'){$where = 'record = '.$_GET['record'];}
                        else if($action=='updating'){
                                    for($inc=0;$inc<count($table_fields);$inc++){
                                                $index = $table_fields[$inc];
                                                $updating[$index] = $_POST[$index];
                                          }
                                    update_record($tb_name,$updating,('record = '.$_POST['record']));
                              }
                  if($action=='delete'||$action=='updating'){echo '<script language="JavaScript" type="text/javascript">parent.editing.document.location=\'registration.php\';</script>';}
                  if(count($listings=retrive_records($tb_name,'*',$where))>0){
                              foreach($listings as $listing){
                                          array_pop($listing);array_pop($listing);
                                          $records[] = $listing;
                                    }
                              echo report_table($tb_name,$table_fields,$records);
                        }else{echo 'There are no records available at this time.<br />The database appears to be empty, please input new records.';}
            }else{echo '<script language="JavaScript" type="text/javascript">top.document.location.href=\'index.html\'</script>';}

?>


This is the code for "required.inc"


<?php

      define('_emp_','');
      define('_spc_',' ');
      define('_nl_',"\n");
      define('_tab_',"\t");
      define('_brk_','<br />');
      define('_blank_','&nbsp;');
      function authenticate(){
                  if(!$authorized){
                              if((substr($_SERVER['SERVER_SOFTWARE'],0,9)=="Microsoft")&&(!isset($_SERVER['PHP_AUTH_USER']))&&(!isset($_SERVER['PHP_AUTH_PW']))&&(substr($_SERVER['HTTP_AUTHORIZATION'],0,6)=="Basic")){list($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'])=explode(":",base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'],6)));}
                              if(($_SERVER['PHP_AUTH_USER']==='admin')&&($_SERVER['PHP_AUTH_PW']==='demo')){$authorized=true;}
                                    else{
                                                header('WWW-Authenticate: Basic realm="Administration"');
                                                if(substr($_SERVER['SERVER_SOFTWARE'],0,9)=="Microsoft"){header("Status: 401 Unauthorized");}
                                                      else{header("HTTP/1.0 401 Unauthorized");}
                                                $authorized=false;
                                          }
                        }
                  $_SESSION['authorized']=$authorized;
            }
      function connect_to_database($db_host,$db_login,$db_password){
                  mysql_pconnect($db_host,$db_login,$db_password);
            }
      function use_database($db_name){
                  mysql_query('USE '.$db_name);
            }
      function scriptless_record($record){
                  foreach($record as $field=>$content){
                              if(preg_match("/script/",$content)){$content=preg_replace("/script/",_emp_,$content);}
                              $validated[$field]=$content;
                        }
            return($validated);
            }
      function insert_record($tb_name,$tb_fields,$flds_values){
                  $flds_values=scriptless_record(array_values($flds_values));
                  foreach($flds_values as $field=>$value){$flds_values[$field]=htmlentities(addslashes(trim(nl2br($value))),ENT_QUOTES);}
                  $tb_fields=implode(',',$tb_fields);
                  $flds_values=implode("','",$flds_values);
                  mysql_query("INSERT INTO ".$tb_name." ( ".$tb_fields." ) VALUES ( '".$flds_values."' );");
            }
      function get_table_fields($db_name,$tb_name){
                  $fields;$columns;$xecho;
                  $fields=mysql_list_fields($db_name,$tb_name);
                  $columns=mysql_num_fields($fields);
                  for($i=0;$i<$columns;$i++){$xecho[$i]=mysql_field_name($fields,$i);}
            return($xecho);
            };
      function retrive_records($table,$fields='*',$condition=false,$format='array'){
                  $result=mysql_query('SELECT '.$fields.' FROM '.$table.(($condition)?(' WHERE '.$condition):('')).' ORDER BY record ASC;');
                  $records=mysql_num_rows($result);
                  if(count($records)>0){
                              for($inc=0;$inc<$records;$inc++){$retrived[$inc]=($format=='object')?(mysql_fetch_object($result)):(mysql_fetch_array($result,MYSQL_ASSOC));}
                              return($retrived);
                        }else{return(false);}
            }
      function update_record($tb_name,$tb_content,$condition=false){
                  $tb_content=scriptless_record($tb_content);
                  if(count($tb_content)>1){array_shift($tb_content);}
                  foreach($tb_content as $field=>$attribute){$update[]=$field." = '".$attribute."'";}
                  mysql_query('UPDATE '.$tb_name.' SET '.join(', ',$update).(($condition)?(' WHERE '.$condition):('')).';');
            }
      function remove_record($tb_name,$condition){
                  mysql_query('DELETE FROM '.$tb_name.' WHERE '.$condition.';');
            }
      function mysq_php_timestamp($indexes,$formats,$tb_name,$timestamp,$record_id){
                  $date_format=explode(' ',array_shift(mysql_fetch_row(mysql_query("SELECT DATE_FORMAT( ".$timestamp.", ".$formats." ) FROM ".$tb_name." WHERE record = '".$record_id."';"))));
                  $timestamp=array();
                  foreach($date_format as $index=>$format){$timestamp[$indexes[$index]]=$format;}
            return($timestamp);
            }
      function report_table($tb_name,$table_fields,$listings){
                  if(count($listings)>0){
                              $tb_body=array();
                              $swap=true;
                              foreach($listings as $listing){
                                          $tb_tr=array();
                                          $tb_tr[]='<tr>';
                                          $color=($swap)?('on'):('off');
                                          $rec_id=array_shift($listing);
                                          $index=array();
                                          $index[]='<td id="'.$rec_id.'" class="cell_'.$color.'" style="text-align:right;padding:0px 0px;background:#d4d0c8">';
                                          $features='<table border="0" align="right" cellpadding="0" cellspacing="0"><tr><td><label style="font-size:10pt;color:#000000;">'.$rec_id.'&nbsp;</label></td>';
                                          if($_GET['action']=='editing'){
                                                      $features.='<td><input type="image" border="0" name="updating" src="images/save01.gif" alt="Save Changes"><input type="hidden" name="record" value="'.$rec_id.'"></td>';
                                                }
                                                else{
                                                            $timestamp=mysq_php_timestamp(array('weekday','month','monthday','year','time','section'),"'%W %M %D %Y %T %p'",$tb_name,'timestamp',$rec_id);
                                                            $timestamp=$timestamp['weekday'].', '.$timestamp['month'].' '.$timestamp['monthday'].'. '.$timestamp['year'].' - '.$timestamp['time'].' '.$timestamp['section'];
                                                            $features.='<td><a href="'.$_SERVER['PHP_SELF'].'?action=editing&record='.$rec_id.'" target="editing"><img id="" class="" src="images/edit01.gif" border="0" alt="Edit Record: '.$timestamp.'" /></a></td>';
                                                      }
                                          $features.='<td><a href="./confirmation.php?action=delete&record='.$rec_id.'" target="report"><img id="" class="" src="images/delete01.gif" border="0" alt="Delete Record" /></a></td></tr></table>';
                                          $index[]=$features.'</td>';
                                          $tb_tr[]=join(_nl_,$index);
                                          $tr_td=array();
                                          foreach($listing as $index=>$record){
                                                      if($_GET['action']=='editing'){
                                                                  $tr_td[]='<td style="padding:0px 2px;background:#d4d0c8" valign="top">';
                                                                  if($index!=='comments'){$tr_td[]='<input class="txt" name="'.$index.'" type="text" size="20" value="'.htmlentities(stripslashes($record),ENT_QUOTES).'"></td>';}
                                                                        else{$tr_td[]='<textarea id="'.$index.'_'.$rec_id.'" class="txt" name="'.$index.'" rows="5" wrap="virtual">'.htmlentities(stripslashes($record),ENT_QUOTES).'</textarea>';}
                                                                  $tr_td[]='</td>';
                                                            }else{
                                                                        $tr_td[]='<td id="'.$index.'" class="cell_'.$color.'" valign="top">';
                                                                        $link=(($color=='on')?('#ffffff'):('#6989A8'));
                                                                        if($index==='e_mail'){
                                                                                    $contact=(!empty($listing['first_name'])?($listing['first_name'].' '):(_emp_)).(!empty($listing['last_name'])?($listing['last_name'].' '):(_emp_)).(!empty($listing['alias'])?("- ".$listing['alias']):(_emp_));
                                                                                    $tr_td[]='<a id="" style="color:'.$link.';text-decoration:none;" href="mailto:'.$contact.'<'.$record.'>">'.$record.'</a>';
                                                                              }
                                                                              else if(strstr($record,"http://")){$tr_td[]='<a id="" style="color:'.$link.';text-decoration:none;" href="'.$record.'" target="portfolio">'.$record.'</a>';}
                                                                              else{
                                                                                          $booled=strtoupper($record);
                                                                                          if(empty($record)){$tr_td[]='&nbsp;';}
                                                                                                else if(($booled=='TRUE')||($booled=='FALSE')){$tr_td[]=($booled=='TRUE')?('Yes'):('No');}
                                                                                                else{$tr_td[]=stripslashes(html_entity_decode($record));}
                                                                                    }
                                                                        $tr_td[]='</td>';
                                                                  }
                                                }
                                          $tb_tr[]=join(_nl_,$tr_td).'</tr>';
                                          $tb_body[]=join(_nl_,$tb_tr);
                                          $swap=!$swap;
                                    }
                        }
                  $tb_head=array();
                  $tb_head[]='<tr>';
                  $tr_td=array();
                  foreach($table_fields as $field){
                              $tr_td[]='<td id="'.$field.'" class="header" nowrap>';
                              $column=ucwords(strtolower(str_replace('_',_spc_,$field)));
                              if($column=='Record'){$column=(count($listings)>1)?('Recs( '.count($listings).' )'):('Rec( 1 )');}
                              $tr_td[]=$column.'</td>';
                        }
                  $tb_head[]=join(_nl_,$tr_td).'</tr>';
                  $report=array();
                  if(count($tb_body)>0){
                              $report[]='<table bordercolor="#6989A8" border="1" align="left" cellpadding="2" cellspacing="0">'.join(_nl_,$tb_head).join(_nl_,$tb_body).'</table>';
                              $output=array();
                              if($_GET['action']=='editing'){
                                          $form[]='<form name="updating" action="./management.php?action=updating" method="POST" target="report" enctype="application/x-www-form-urlencoded">'.join(_nl_,$report).'</form>';
                                          $output=join(_nl_,$form);
                                    }else{$output=join(_nl_,$report);}
                        }else{$output='No records were found!';}
            return($output);
            }
      function tracer($content){
                  echo '<pre>';
                  var_dump($content);
                  echo '</pre>';
            }

?>


[+][-]12/28/03 09:37 PM, ID: 10009291Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/28/03 11:14 PM, ID: 10009453Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/29/03 06:24 AM, ID: 10010599Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP Scripting Language
Tags: php, base64_decode, header
Sign Up Now!
Solution Provided By: lozloz
Participating Experts: 1
Solution Grade: A
 
[+][-]12/29/03 07:32 AM, ID: 10010997Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/29/03 03:23 PM, ID: 10013563Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/29/03 04:19 PM, ID: 10013750Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/29/03 04:41 PM, ID: 10013801Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/29/03 09:19 PM, ID: 10014587Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/30/03 05:47 AM, ID: 10016022Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/30/03 07:34 AM, ID: 10016551Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/30/03 07:58 AM, ID: 10016677Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/30/03 11:50 AM, ID: 10018032Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/30/03 12:09 PM, ID: 10018130Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/30/03 12:50 PM, ID: 10018403Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/30/03 04:03 PM, ID: 10019173Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/30/03 05:34 PM, ID: 10019443Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/30/03 05:42 PM, ID: 10019464Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/30/03 06:02 PM, ID: 10019560Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/30/03 06:43 PM, ID: 10019701Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/30/03 06:45 PM, ID: 10019706Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/30/03 06:48 PM, ID: 10019715Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/30/03 06:48 PM, ID: 10019720Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81