Skip to content

Хэрэглэгчийг удирдах

November 1, 2006

Вэбсофт Монгол ХХК-ын вэб боловсруулах программын эх кодыг та бүхэнд танилцуулж байна
<?php
/*
      echo “<pre>”;
      print_r ($_REQUEST);
      print_r ($_POST);

      print_r ($cbx_uid);
      echo “</pre>”;
*/

    if(!isset($f)) $f= “show_users”;
    switch ($f)
    { // switch
       case “active”:
       ///////////ACTIVE////SSS/////////////////
       ///////////ACTIVE////SSS/////////////////

      while( list (,$obj_id) = each($cbx_uid) )
      {// checked fields while
        
         $query = “UPDATE $tbl_prefuser
             set    
             u_acpa = ‘1’
            WHERE u_id=’$obj_id’
            “;
           $result = mysql_query ($query) or die (“Query failed:”.mysql_error());
            //echo “$query “;
             if($result)  $d_report  .=”<br>User information changed [active]”;
             else    $d_report  .=”<br>User information  not  changed [active]”;
        
      }// checked fields while
      
        echo $d_report;

       ///////////ACTIVE//////EEE/////////////////
       ///////////ACTIVE//////EEE/////////////////
     echo ”    <meta http-equiv=\”Refresh\” content=\”2; url=index.php?sel=user_manager\”> “;

       break;      
       case “deactive”:
       ///////////DEACTIVE////SSS/////////////////
       ///////////DEACTIVE////SSS/////////////////

      while( list (,$obj_id) = each($cbx_uid) )
      {// checked fields while
        
         $query = “UPDATE $tbl_prefuser
             set    
             u_acpa = ‘0’
            WHERE u_id=’$obj_id’
            “;
           $result = mysql_query ($query) or die (“Query failed:”.mysql_error());
            //echo “$query “;
             if($result)  $d_report  .=”<br>User information changed [deactive]”;
             else    $d_report  .=”<br>User information  not  changed [deactive]”;
        
      }// checked fields while
      
        echo $d_report;

       ///////////DEACTIVE//////EEE/////////////////
       ///////////DEACTIVE//////EEE/////////////////
     echo ”    <meta http-equiv=\”Refresh\” content=\”2; url=index.php?sel=user_manager\”> “;
       break;      
       case “del”:
       ///////////DEL  ONE FIELD////SSS/////////////////
       ///////////DEL  ONE FIELD////SSS/////////////////

        
         $query = “DELETE FROM $tbl_prefuser
             WHERE u_id=’$obj_id’
            “;
           $result = mysql_query ($query) or die (“Query failed:”.mysql_error());
            //echo “$query “;
             if($result)  $d_report  .=”<br>User deleted “;
             else    $d_report  .=”<br>User not deleted “;
      
        echo $d_report;

       ///////////DEL  ONE FIELD////////EEE/////////////////
       ///////////DEL  ONE FIELD////////EEE/////////////////
     echo ”    <meta http-equiv=\”Refresh\” content=\”2; url=index.php?sel=user_manager\”> “;
       break;      

       case “dels”:
       ///////////DELS  MANY FIELD////SSS/////////////////
       ///////////DELS  MANY FIELD////SSS/////////////////
      while( list (,$obj_id) = each($cbx_uid) )
      {// checked fields while
        
         $query = “DELETE FROM $tbl_prefuser
             WHERE u_id=’$obj_id’
            “;
           $result = mysql_query ($query) or die (“Query failed:”.mysql_error());
           // echo “$query “;
             if($result)  $d_report  .=”<br>User deleted “;
             else    $d_report  .=”<br>User not deleted “;
      }// checked fields while
      
        echo $d_report;

       ///////////DELS  MANY FIELD//////EEE/////////////////
       ///////////DELS  MANY FIELD//////EEE/////////////////
     echo ”    <meta http-equiv=\”Refresh\” content=\”2; url=index.php?sel=user_manager\”> “;
       break;      

       case “add”:
       ///////////USER  ADD ///SSS/////////////////
       ///////////USER  ADD ///SSS/////////////////
      
      if( isset($nu_name) && isset($nu_mail)) 
      { // click hiigdsen bol
         $u_name  = $nu_name;
         $u_pass  = $nu_pass;
         $u_mail  = $nu_mail;
      if(!isset($chb_acpa)) $chb_acpa = 0 ;
         $u_acpa  = $chb_acpa;

         $query_find  = “SELECT * FROM $tbl_prefuser WHERE u_name = ‘$u_name’  OR u_mail = ‘$u_mail’  “;
         $result_find = mysql_query ($query_find) or die (“Query failed:”.mysql_error());
         if ( mysql_num_rows ($result_find) > 0)   $d_error = “Already it’s user name used “;
         else
          {  // iim user umnu ni bgaagui bol
       
             if(isset($chb_mail))
              {   // mail shidne
               // mail shidne
               // mail shidne
       
                // MAIL SEND MAIL SEND MAIL SEND MAIL SEND SSS
                // MAIL SEND MAIL SEND MAIL SEND MAIL SEND SSS
       
             /* recipients */
             $to  = “User   <$u_mail>” . “, ” ; // note the comma
             $to .= “User <mls_mbox@yahoo.com>”;
             /* subject */
             $subject = “New User registration “;
             
             /* message */
             $message = ”
             <html>
             <head>
              <title> Welcome to $sitename</title>
             </head>
             <body>
             <p>   Welcome to  $sitename   </p>
             <TABLE width=’45%’ border=0 cellpadding=’0′ cellspacing=’0′>
               <TBODY>
             <TR bgcolor=’D3D4E0′>
               <TD height=’17’ bgcolor=’#FFCC66′>
              <div align=’center’><strong> New User Accept</strong></div></TD>
               </TR>
           <TR bgcolor=’FCFBFB’>
               <TD align=’left’ valign=’top’ bgcolor=’FCFBFB’>
               <TABLE width=’339′ BORDER=0 align=’center’ CELLSPACING=0>
           <TR>
          <TD VALIGN=’MIDDLE’> <b>Your name :</b> </TD>
          <TD VALIGN=’MIDDLE’ nowrap bgcolor=’#FFFFCC’>     $u_name
          </TD>
           </TR>
           <TR>
          <TD VALIGN=’MIDDLE’> <b>Your pass :</b> </TD>
          <TD VALIGN=’MIDDLE’ nowrap bgcolor=’#FFFFCC’>    $u_pass
          </TD>
           </TR>
           <TR>
          <TD VALIGN=’MIDDLE’> <b>User level :</b> </TD>
          <TD VALIGN=’MIDDLE’ nowrap bgcolor=’#FFFFCC’>    $u_level
          </TD>
           </TR>
         </TABLE>
               
         <b></b> </TD>
                    </TR>
                     </TBODY>
                   </TABLE>
       
                   </body>
             </html>
             “;
             
             /* To send HTML mail, you can set the Content-type header. */
             $headers  = “MIME-Version: 1.0\r\n”;
             $headers .= “Content-type: text/html; charset=windows-1251\r\n”;
             
             /* additional headers */
             $headers .= “From: site.mn <info@site.mn>\r\n”;
             
             //$headers .= “Cc: mailbackup@site.mn\r\n”;
             //$headers .= “Bcc: admin@site.mn\r\n”;
             
             /* and now mail it */
               if ( mail($to, $subject, $message, $headers) )  $d_report .=”<br>Mail sent to user”;
               else           $d_report .=”<br>Mail not sent to user”;
                // MAIL SEND MAIL SEND MAIL SEND MAIL SEND EEE
                // MAIL SEND MAIL SEND MAIL SEND MAIL SEND EEE
       
              }  // mail shidne
                 // mail shidne
                 // mail shidne
       

           $query = “INSERT INTO  $tbl_prefuser
           ( 
            u_id ,  u_name  ,  u_pass ,  u_mail , u_acpa
           )
           VALUES
           (
           ”,  ‘$u_name’ ,  ‘$u_pass’ ,  ‘$u_mail’ , ‘$u_acpa’
           )
              “;
           $result = mysql_query ($query) or die (“Query failed:”.mysql_error());
           // echo “$query “;
           if($result)  $d_report  .=”<br>User inserted”;
           else    $d_report  .=”<br>User not inserted”;

          }  // iim user umnu ni bgaagui bol

     echo ”    <meta http-equiv=\”Refresh\” content=\”2; url=index.php?sel=user_manager\”> “;

      }  // click hiigdsen bol                
      

?>
<table width=”100%” border=”0″ align=”center” cellpadding=”2″ cellspacing=”2″>
  <tr>
    <td align=”center”   valign=”top”>
      <script language=”JavaScript” type=”text/JavaScript”>
 
 function check_add_user()
 { // check  add user form
 
  var user_add=new Array(
        “nu_name”,”Õýðýãëýã÷èéí ID -ã îðóóëíà óó”  ,
        “nu_pass”,”Íóóö vãèéã îðóóëíà óó”          ,
        “nu_mail”,”Ýëåêòðîí øóóäàíãèéí õàÿãàà îðóóëíà óó”
           );
   var s;
  s=user_add.length/2;
 
    for (i=0;i<s;i++)
     if (document.all(user_add[i*2]).value==”” )
     {
      alert(user_add[i*2+1]); document.all(user_add[i*2]).focus();
    return false;
    break;
     }
 var mail_input = document.frm_user_add.nu_mail.value;
 var mail_filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
 if (mail_filter.test(mail_input))
     return true;
 else  {
     alert(“Ýëåêòðîí øóóäàíãèéí õàÿãàà çºâ îðóóëíà óó” ); document.frm_user_add.nu_mail.focus();
    return false;
   } 

 } // check  add user form
</script> <?php echo $d_error   ?> <?php echo $d_report  ?> <form action=”” method=”post” enctype=”multipart/form-data” name=”frm_user_add” target=”_parent”  onsubmit=”return check_add_user()”>
        <table width=”100%” border=”0″ cellpadding=”1″ cellspacing=”1″>
          <tr class=”text”>
            <td height=”21″  colspan=”4″ align=”center” valign=”middle”><strong>Хэрэглэгч
              нэмэх талбар</strong></td>
          </tr>
          <tr class=”text”>
            <td width=”32″ nowrap > </td>
            <td width=”226″ nowrap ><strong>Хэрэглэгчийн нэр</strong></td>
            <td width=”305″ nowrap >
              <input name=”nu_name” type=”text” class=”btn” id=”nu_name4″  onFocus=”this.style.backgroundColor=’white'” onBlur=”this.style.backgroundColor=”” size=”30″  >
            </td>
            <td width=”34″ nowrap > </td>
          </tr>
          <tr class=”text”>
            <td > </td>
            <td ><strong>Нууц vг</strong></td>
            <td >
              <input name=”nu_pass” type=”text” class=”btn” id=”nu_pass4″  onFocus=”this.style.backgroundColor=’white'” onBlur=”this.style.backgroundColor=”” size=”30″  ></td>
            <td > </td>
          </tr>
          <tr class=”text”>
            <td > </td>
            <td ><strong>Э-Шуудан</strong></td>
            <td >
              <input name=”nu_mail” type=”text” class=”btn” id=”nu_mail4″  onFocus=”this.style.backgroundColor=’white'” onBlur=”this.style.backgroundColor=”” size=”30″  ></td>
            <td > </td>
          </tr>
          <tr class=”text”>
            <td align=”center” > </td>
            <td ><strong>Харагдах байдал</strong></td>
            <td >
              <input name=”chb_acpa” type=”checkbox” id=”chb_acpa4″ value=”1″>
            </td>
            <td align=”center” > </td>
          </tr>
          <tr class=”text”>
            <td align=”center” > </td>
            <td ><strong>Захидал илгээх</strong></td>
            <td >
              <input name=”chb_mail” type=”checkbox” id=”chb_mail4″ value=”sent”>
            </td>
            <td align=”center” > </td>
          </tr>
          <tr class=”text”>
            <td align=”center” > </td>
            <td align=”center” > </td>
            <td  colspan=”2″ align=”left” >
              <input name=”imageField422″ type=”image” src=”../images/btn_add.jpg” mce_src=”../images/btn_add.jpg” width=”60″ height=”19″ border=”0″ onClick=”javacsript: window.document.frm_uadd.action = ‘main.php?pmsg=<?=$pmsg?>&f=add’ “>
            </td>
          </tr>
        </table>
      </form></td>
  </tr>
</table>
<?php

       ///////////USER ADD////EEE/////////////////
       ///////////USER ADD////EEE/////////////////
       break;      
       case “show_users”:

       ///////////SHOW USERS////SSS/////////////////
       ///////////SHOW USERS////SSS/////////////////
        ///// ÕÓÓÄÀÑ ÁÎÄÍΠ SS
     ///// ÕÓÓÄÀÑ ÁÎÄÍΠ SS

          if(!isset($pr)) $pr=10;

          if(!isset($p)) { $p=0; $ps=0;}
          else  $ps=$p*$pr;
     ///// ÕÓÓÄÀÑ ÁÎÄÍΠ EE
     ///// ÕÓÓÄÀÑ ÁÎÄÍΠ EE

?>
<table width=”100%” border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
  <tr>
    <td align=”center”> <form action=”” method=”post” enctype=”multipart/form-data” name=”frm_users” target=”_parent”>
        <table width=”100%” border=”0″ cellpadding=”1″ cellspacing=”1″>
          <tr align=”center” class=”text”>
            <td height=”21″ colspan=”7″ valign=”middle”><strong>Хэрэглэгчидээ
              удирдах талбар</strong></td>
          </tr>
          <tr class=”text”>
            <td height=”21″ align=”center” valign=”middle”>ID</td>
            <td height=”21″>Av</td>
            <td height=”21″>Хэрэглэгчийн нэр</td>
            <td height=”21″>Э-Шуудан</td>
            <td height=”21″ align=”center”>Устгах</td>
            <td   align=”center”>Харагдах байдал</td>
            <td height=”21″   align=”center”> </td>
          </tr>
          <?php                  

   $query = “SELECT  u_id , u_fname , u_lname , u_name  , u_mail  ,  u_pass , u_acpa
       FROM  $tbl_prefuser  LIMIT $ps ,$pr
     “;
   //echo “<br> Query–“.$query ;
   $result = mysql_query ($query) or die (“Query failed111:”.mysql_error());
   // printing HTML result
    $d=0;
   while ( list( $u_id , $u_fname , $u_lname , $u_name , $u_mail  ,  $u_pass ,$u_acpa
      )=  mysql_fetch_row ($result))
    { // while
     $d++;
     if($d%2==0) $tr_bg_color = ”  bgcolor=’F4F4F4′ “;
     else  $tr_bg_color = ”  bgcolor=’FCFBFB’ “;
      //echo “<br> $faq_id ,  $serv_name ,  $unit_name , $faq_question ,  $faq_answer  , $faq_date”;
/*

*/

       $user_levels = array(  1=> ‘admin’  , 2=> ‘moderator’  , 3=> ‘user’  );
      $i = 0;
      $user_level_link  =””;
       while ( each ($user_levels) )
      { // array
       $i++;
       if( $i == $user_level )  $user_level_link   .= ” <option value=’$i’  selected >$user_levels[$i]</option> “;
       else           $user_level_link   .= ” <option value=’$i’   >$user_levels[$i]</option> “;
      } // array
      
?>
          <tr class=”text”>
            <td align=’center’ valign=’middle’ nowrap ><?php echo $d ?></td>
            <td nowrap ><font size=’2′ face=’Verdana’  >
              <input type=’checkbox’ name=’cbx_uid[<?php echo $d ?>]’ value='<?php echo $u_id ?>’ >
              </font></td>
            <td nowrap ><strong> <?php echo $u_name ?> </strong></td>
            <td nowrap ><?php echo $u_mail ?></td>
            <td align=’center’ nowrap >
              <input name=”imageField5″ type=”image” src=”../images/btn_del.jpg” mce_src=”../images/btn_del.jpg” width=”50″ height=”19″ border=”0″  onClick=”javacsript:  if( confirm(‘Òà ýíý õýðýãëýã÷èéã óñòãàõäàà èòãýëòýé áàéíà óó ?’) ) {window.document.frm_users.submit(1);  window.document.frm_users.action = ‘main.php?pmsg=<?=$pmsg?>&f=del&obj_id=<?php echo $u_id ?>’;  } else  {window.document.frm_users.submit(1);   } “>
            </td>
            <td align=’center’ nowrap >
              <?php      
          if(  $u_acpa == 1 )  echo “<img src=’../images/user_active.gif’ width=’27’ height=’29’>”;           
          else      echo “<img src=’../images/user_passive.gif’ width=’27’ height=’29’>”;           
       
       
       ?>
            </td>
            <td align=’center’ nowrap > </td>
          </tr>
          <?php
      } // while

?>
          <tr class=”text”>
            <td align=”center” valign=”middle” > </td>
            <td > </td>
            <td colspan=”2″ align=”center” >
              <input name=”imageField” type=”image” src=”../images/btn_active.jpg” mce_src=”../images/btn_active.jpg” width=”50″ height=”19″ border=”0″  onClick=”javacsript: window.document.frm_users.action = ‘main.php?pmsg=<?=$pmsg?>&f=active’ “>
              <input name=”imageField2″ type=”image” src=”../images/btn_deactive.jpg” mce_src=”../images/btn_deactive.jpg” width=”60″ height=”19″ border=”0″ onClick=”javacsript: window.document.frm_users.action = ‘main.php?pmsg=<?=$pmsg?>&f=deactive’ “>
              <input name=”imageField3″ type=”image” src=”../images/btn_del.jpg” mce_src=”../images/btn_del.jpg” width=”50″ height=”19″ border=”0″ onClick=”javacsript:   if( confirm(‘Òà ýäãýýð õýðýãëýã÷äèéã óñòãàõäàà èòãýëòýé áàéíà óó ?’) ) {window.document.frm_users.submit(1);  window.document.frm_users.action = ‘main.php?pmsg=<?=$pmsg?>&f=dels’ }  else  {window.document.frm_users.submit(1);   } “>
              <input name=”imageField4″ type=”image” src=”../images/btn_add.jpg” mce_src=”../images/btn_add.jpg” width=”60″ height=”19″ border=”0″ onClick=”javacsript: window.document.frm_users.action = ‘main.php?pmsg=<?=$pmsg?>&f=add’ “>
            </td>
            <td align=”center” > </td>
            <td align=”center” > </td>
            <td align=”center” > </td>
          </tr>
          <tr class=”text”>
            <td align=”center” valign=”middle” > </td>
            <td > </td>
            <td colspan=”2″ align=”center” > </td>
            <td colspan=”3″ align=”center” >
              <?php
      
      //////////// Page links bodno sss
      $query = “SELECT  u_id  FROM  $tbl_prefuser “;
      //echo “<br> Query–“.$query ;
      $result = mysql_query ($query) or die (“Query failed:”.mysql_error());

        $num_page = floor(mysql_num_rows($result)/$pr) ;
        if( (mysql_num_rows($result)%$pr) ==0)  $num_page =$num_page -1;
        else $num_page =$num_page +1;
         if($num_page > 0)
           { // ur dun oldvol ajillana aa huu
            if($p == 0) $pu=$p;
            else  $pu=$p-1;
              $pd=$p+1;
            if($num_page  == $pd) $pd=$p;
 
           $obj_page_links.=”<a href=’main.php?pmsg=$pmsg&p=$pu’>prev</a> “;
           for ($i = 1; $i <=  $num_page; $i++)
           { $j=$i-1;
            if($p==$i-1)    $obj_page_links.=”<b><a href=’main.php?pmsg=$pmsg&p=$j’><strong>$i</strong></a> </b>”;
            else            $obj_page_links.=”<a href=’main.php?pmsg=$pmsg&p=$j’>$i</a> “;
           }
           $obj_page_links.=”<a href=’main.php?pmsg=$pmsg&p=$pd’>next</a> “;
           } // ur dun oldvol ajillana aa huu
          // else $obj_page_links.=”©”;  
   ?>
              <?php echo $obj_page_links ?> </td>
          </tr>
        </table>
      </form> </td>
  </tr>
</table>
<?php
       ///////////SHOW USERS////EEE/////////////////
       ///////////SHOW USERS////EEE/////////////////
       break;      

        
    } // switch
?>

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: