⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phpmyedit.inc

📁 一款linux下的PHP编制器 十分实用
💻 INC
📖 第 1 页 / 共 3 页
字号:
                $x = $this->set_values_from_table($this->db,
                  $this->tb.','.$this->fdd[$this->fds[$k]]['values']['table'],
                  $this->fdd[$this->fds[$k]]['values']['table'].'.`'.$this->fdd[$this->fds[$k]]['values']['column'].'`',
                  $this->fdd[$this->fds[$k]]['values']['table'].'.`'.$this->fdd[$this->fds[$k]]['values']['description'].'`',
                  ' WHERE ('.$this->fdd[$this->fds[$k]]['values']['table'].'.`'.$this->fdd[$this->fds[$k]]['values']['column'].'` = '.$this->tb.'.`'.$fd.'`)');

              } else {
                $x = $this->set_values_from_table ($this->db, $this->tb, '`'.$fd.'`');
              }
/*            
              Multiple fields processing - default size is 2 and array required for values
*/												
												if (!isset($this->multiple)) {$this->multiple=2;}
              if ($this->fdd[$fd]['select'] == 'M')
												{ $a = ' multiple size="'.$this->multiple.'"'; } else { $a=''; }
              echo '      <td><select'.$a.' name="qf'.$k.'[]" size="1">'."\n";

              if (( is_array($m) and in_array('*',$m))
												or  ($m == '*')) {
                echo '            <option value="*" selected>*</option>'."\n";
              } else {
                echo '            <option value="*">*</option>'."\n";
              }

              for ($j = 0; $j < count ($x['option']); $j++) {
                if (is_array($m))
                {
                  if (in_array($x['value'][$j],$m)) {
                    echo '            <option selected>'.$x['value'][$j].'</option>'."\n";
                  } else {
                    echo '            <option>'.$x['value'][$j].'</option>'."\n";
                  }
														} else {
                  if ($x['value'][$j] == $m) {
                    echo '            <option selected>'.$x['value'][$j].'</option>'."\n";
                  } else {
                    echo '            <option>'.$x['value'][$j].'</option>'."\n";
                  }
														}
              } /* for */

              echo '          </select></td>'."\n";

            } elseif ($this->fdd[$fd]['select'] == 'T') {

              echo '      <td><input type="text" name="qf'.$k.'"';
              echo ' value="'.$m.'"';

              if (mysql_field_type ($res, $k) != 'blob') {
                echo ' size="'.mysql_field_len($res,$k).'"';
                echo ' maxlength="'.mysql_field_len($res,$k).'"';
              }
              echo ' /></td>'."\n";
            } else {
              echo '      <td>&nbsp;</td>'."\n";
            } /* if elseif else */

          } /* end if bro1 */
        } /* for */

        echo '    </tr>'."\n";
        echo '    <tr>'."\n";

      } /* if first and fl */

      if ($select_recs) {
        if ($first) {
          echo '      <td><input checked type="radio" name="rec" value="'.$row[$this->key].'" /></td>'."\n";
        } else {
          echo '      <td><input type="radio" name="rec" value="'.$row[$this->key].'" /></td>'."\n";
        }
      } elseif ($this->filter_enabled ()) {
        echo '      <td>&nbsp;</td>'."\n";
      }

      $first = false;
      for ($k = 0; $k < $this->num_fds; $k++) {
        $fd = $this->fds[$k];
        if (stristr($this->fdd[$fd]['options'],'L') or !isset($this->fdd[$fd]['options'])) {
          if ((trim ($row[$k]) == '') or ($row[$k] == 'NULL')) {
            echo '      <td>&nbsp;</td>'."\n";
          } else {
            $row[$k] = nl2br(htmlentities ($row[$k]));
            /* Make clickable items clickable */
            if (!isset($this->fdd[$this->fds[$k]]['URL'])) {
              echo '      <td>'.$row[$k].'</td>'."\n";
            } else {
              echo '      <td><a href="'.$this->fdd[$this->fds[$k]]['URL'].$row[$k].'">'.$row[$k].'</a></td>'."\n";
            }
          } /* if else */
        } /* if */
      } /* for */

      echo '    </tr>'."\n";
      --$eot;
    } /* while */

    echo '  </table>'."\n";
    /* note that <input disabled isn\'t valid HTML but most browsers support it */
    echo "  <hr />\n  <table summary=\"nav buttons\"><tr>\n";
    if ($this->fm > 0) {
      echo '    <td><input type="submit" name="prev" value="'.$this->labels[0].'" /></td>'."\n";
    } else {
      echo '    <td><input disabled type="submit" name="dprev" value="'.$this->labels[0].'" /></td>'."\n";
    }
    if ($this->add_enabled ()) {
      echo '    <td><input type="submit" name="operation" value="'.$this->labels[1].'" /></td>'."\n";
    }
    if ($first) {
      if ($this->change_enabled ()) {
        echo '    <td><input disabled type="submit" name="doperation" value="'.$this->labels[2].'" /></td>'."\n";
      }
      if ($this->delete_enabled ()) {
        echo '    <td><input disabled type="submit" name="doperation" value="'.$this->labels[3].'" /></td>'."\n";
      }
    } else {
      if ($this->change_enabled ()) {
        echo '    <td><input type="submit" name="operation" value="'.$this->labels[2].'" /></td>'."\n";
      }
      if ($this->delete_enabled ()) {
        echo '    <td><input type="submit" name="operation" value="'.$this->labels[3].'" /></td>'."\n";
      }
    } /* if else */

    if ($eot == 0) {
      echo '    <td><input type="submit" name="next" value="'.$this->labels[4].'" /></td>'."\n";
    } else {
      echo '    <td><input disabled type="submit" name="dnext" value="'.$this->labels[4].'" /></td>'."\n";
    }
/* 
    Display the current page and the total pages
*/
    echo '    <td>&nbsp;</td>'."\n";
    $total = 0;
    $qry = 'select count(*) as nbrecno '.$this->create_from_clause($this->tb,$this->fdd).$qry_select;
    // echo('<p>'.$qry.'</p>');
    $res = mysql_db_query($this->db, $qry);
    while ($row = mysql_fetch_row($res)) {
      $values[] = $row[0];
    }
    $total = $values[0];
    echo '    <td>&nbsp;'.$this->labels[5].': '.(($this->fm/$this->inc)+1).' / '.Ceil($total/$this->inc).'</td>'."\n";
    echo '    <td>&nbsp;'.$this->labels[6].': '.$total.'</td>'."\n";
    echo '  </tr></table>'."\n";
    echo '</form>'."\n";
  }

  function display_record()
  {
    $this->create_javascripts();

    echo '<table border="1" cellpadding="1" cellspacing="0" summary="'.$this->tb.'">'."\n";
    echo '  <input type="hidden" name="rec" value="'.$this->rec.'" />'."\n";
    echo '  <input type="hidden" name="fm" value="'.$this->fm.'" />'."\n";
    echo '  <input type="hidden" name="sfn" value="'.$this->sfn.'" />'."\n";
    echo '  <input type="hidden" name="fl" value="'.$this->fl.'" />'."\n";
/* 
    preserve the values of any filter fields qf0..qfn for Pass 3 
*/
    for ($k = 0; $k < $this->num_fds; $k++) {
      $l = 'qf'.$k;
      global $$l;
				$m = $this->web2plain($$l);
      if (isset ($m)) 
    		{
        if (is_array($m)) /*multiple selection has been used*/
					 { 
          if (!in_array('*',$m))	/*one '*' in a multiple selection is all you need*/
  								{
  					   for ($n=0; $n<count($m); $n++)
			  			   { 
											  if ($this->plain2web($m[$n]) != '')
              {  echo '  <input type="hidden" name="qf'.$k.'['.$n.']" value="'.$this->plain2web($m[$n]).'">'."\n"; }
            }
				  		}
				  } else {
						  if ($this->plain2web($m) != '')
          { 
								  $this->qfn = $this->qfn.'&qf'.$k.'='.$m;
            echo '  <input type="hidden" name="qf'.$k.'" value="'.$this->plain2web($m).'">'."\n"; 
								}
				  }
      }
    }
    echo '  <input type="hidden" name="qfn" value="'.$this->qfn.'" />'."\n";

    if ($this->add_operation() or $this->more_operation() ) {
      $this->display_add_record ();
    } else {
      $this->display_change_delete_record ();
    }

    echo '</table>'."\n";
    echo '<hr />'."\n";

    if ($this->add_operation() or $this->more_operation()) {
      echo '<input type="submit" name="saveadd" value="'.$this->labels[7].'" />'."\n";
      echo '<input type="submit" name="moreadd" value="'.$this->labels[8].'" />'."\n";
      echo '<input type="button" name="cancel" value="'.$this->labels[9].'" onClick="form.submit();" />'."\n";
    }
    if ($this->change_operation ()) {
      echo '<input type="submit" name="savechange" value="'.$this->labels[7].'" />'."\n";
      echo '<input type="button" name="cancel" value="'.$this->labels[9].'" onClick="form.submit();" />'."\n";
    }
    if ($this->delete_operation ()) {
      echo '<input type="submit" name="savedelete" value="'.$this->labels[3].'" />'."\n";
      echo '<input type="submit" name="cancel" value="'.$this->labels[9].'" />'."\n";
    }
    echo '</form>'."\n";
  }

  function do_add_record()
  {
		$qry = '';
    for ($k = 0; $k < $this->num_fds; $k++) {
      if ( $this->displayed($k) )  
      {
        $fd = $this->fds[$k];
        if ($qry == '') {
          $qry = 'INSERT INTO '.$this->tb.' (`'.$fd.'`';
        } else {
          $qry = $qry.',`'.$fd.'`';
        }
 				 }
    }
		$val = '';
    for ($k = 0; $k < $this->num_fds; $k++) {
      if ( $this->displayed($k) )  
  				{
        $fd = $this->fds[$k];
        $fn = $this->get_http_post_var_by_name($fd);
        if (isset($this->fdd[$fd]['format'])) /*handle fancy date formats*/
        {
								$l = $this->fdd[$fd]['format'][3];  /*delimiter*/
						  $fna = explode($l,$fn);             /*split using user's delim*/
								$fn = $fna[strpos($this->fdd[$fd]['format'],'y')];         /*Year*/
								$fn = $fn.'-'.$fna[strpos($this->fdd[$fd]['format'],'m')]; /*Month*/
								$fn = $fn.'-'.$fna[strpos($this->fdd[$fd]['format'],'d')]; /*Day*/
        }
        if ($val == '') {
          $val = ') VALUES (\''.addslashes($fn).'\'';
        } else {
          $val = $val.',\''.addslashes($fn).'\'';
        }
      }
    }
    $qry = $qry.$val.')';
//  echo '<p>'.$qry.'</p>';
    $res = mysql_db_query ($this->db, $qry);
    echo '<h5>'.mysql_affected_rows().' '.$this->labels[10].'</h5>'."\n";
  }
		
  function do_change_record ()
  {
		$qry = '';
    for ($k = 0; $k < $this->num_fds; $k++) 
		{
      if ( $this->displayed($k) )  
		  {
        $fd = $this->fds[$k];
        $fn = $this->get_http_post_var_by_name($fd);
        if (isset($this->fdd[$fd]['format'])) /*handle fancy date formats*/
        {
						  $l = $this->fdd[$fd]['format'][3];  /*delimiter*/
						  $fna = explode($l,$fn);             /*split using user's delim*/
								$fn = $fna[strpos($this->fdd[$fd]['format'],'y')];         /*Year*/
								$fn = $fn.'-'.$fna[strpos($this->fdd[$fd]['format'],'m')]; /*Month*/
								$fn = $fn.'-'.$fna[strpos($this->fdd[$fd]['format'],'d')]; /*Day*/
        }
        if ($qry == '') {
          $qry = 'UPDATE '.$this->tb.' SET `'.$fd.'`=\''.addslashes($fn).'\'';
        } else {
          $qry = $qry.',`'.$fd.'`=\''.addslashes($fn).'\'';
        }
		  }
    }
    $qry = $qry.' WHERE ('.$this->key.' = '.$this->key_delim.$this->rec.$this->key_delim.')';
//  echo '<p>'.$qry.'</p>';
    $res = mysql_db_query ($this->db, $qry);
    echo '<h5>'.mysql_affected_rows ().' '.$this->labels[2].'</h5>'."\n";
  }
	
  function do_delete_record ()
  {
    $qry = 'DELETE FROM '.$this->tb.' WHERE (`'.$this->key.'` = '.$this->key_delim.$this->rec.$this->key_delim.')';
//  echo '<p>'.$qry.'</p>';
    $res = mysql_db_query ($this->db, $qry);
    echo '<h5>'.mysql_affected_rows ().' '.$this->labels[12].'</h5>'."\n";
  }

  function execute()
  {
    set_magic_quotes_runtime(0); /*let's do explicit quoting ... it's safer */

//  debug code - uncomment to enable

//  phpinfo();
//  $this->print_get_vars();
//  $this->print_post_vars();
//  $this->print_vars();

    if ($this->key_type == 'string' or $this->key_type == 'blob' 
		 or $this->key_type == 'date' or $this->key_type == 'time' 
			or $this->key_type == 'datetime') 
		{ 
		  $this->key_delim = '"';
    } else { 
		  $this->key_delim = ''; 
		}

    $dbl = @mysql_pconnect ($this->hn, $this->un, $this->pw) 
		or die ("<h1>Could not connect to MySQL</h1>\n</body>\n</html>\n");
    if (!isset ($this->db)) 
		{ die ("<h1>No Database defined</h1>\n</body>\n</html>\n"); }
    if (!isset ($this->tb)) 
		{ die ("<h1>No Table defined</h1>\n</body>\n</html>\n"); }
/*
    ======================================================================
    Pass 3: process any updates generated if the user has selected
    a save button during Pass 2
    ======================================================================
*/
    $listit = true;
    if ($this->saveadd == $this->labels[7])
    { $this->do_add_record(); 
		  $listit = false; }
    if ($this->moreadd == $this->labels[8])
    { $this->do_add_record(); }
    if ($this->savechange == $this->labels[7])
    { $this->do_change_record();
		  $listit = false; }
    if ($this->savedelete == $this->labels[3])
    { $this->do_delete_record();
		  $listit = false; }
/*
    ======================================================================
    Pass 2: display an input/edit/confirmation screen if the user has
    selected an editing button on Pass 1 through this page
    ======================================================================
*/
    if ( ($this->add_operation() or $this->more_operation() or 
	        $this->change_operation() or $this->delete_operation() )
		and ( $listit ) ) 
    { $this->display_record(); }
/*
    ======================================================================
    Pass 1 and Pass 3: display the MySQL table in a scrolling window on
    the screen (skip this step in 'Add More' mode)
    ======================================================================
*/
    else
		{ $this->list_table(); }
  }

  function PHPMyEdit($hn, $un, $pw, $db, $tb, $key, $key_type, $inc, $options, $multiple, $fdd, $labels)
  {
/* 
    Instance class variables 
*/
    $this->hn = $hn;
    $this->un = $un;
    $this->pw = $pw;
    $this->db = $db;
    $this->tb = $tb;
    $this->key = $key;
    $this->key_type = $key_type;
    $this->inc = $inc;
    $this->options = $options;
    $this->multiple = $multiple;
    $this->fdd = $fdd;
    $this->labels = $labels;
/*  
    Find the URL to post forms
*/
    global $HTTP_SERVER_VARS;
    $this->page_name =basename($HTTP_SERVER_VARS["PHP_SELF"]);
/* 
    form variables all around 
*/
    global $operation, $apply, $fl, $fm, $sfn, $qfn, $sw, $rec, $prev, $next, $saveadd, $moreadd, $savechange, $savedelete;
    $this->operation = $operation;
    $this->apply = $apply;
    $this->fl = $fl;
    $this->fm = $fm;
    $this->sfn = $sfn;
    $this->qfn = $qfn;
    $this->sw = $sw;
    $this->rec = $rec;
    $this->prev = $prev;
    $this->next = $next;
    $this->saveadd = $saveadd;
    $this->moreadd = $moreadd;
    $this->savechange = $savechange;
    $this->savedelete = $savedelete;
/*  
    Extract SQL Field Names and number of fields 
*/
    foreach ($this->fdd as $akey => $aval) 
		{ $this->fds[] = $akey; }
    $this->num_fds = sizeof ($this->fds);
  }
} /* End of class */

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -