index.php 4.63 KB
Newer Older
majidbeigi's avatar
majidbeigi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
<?php

	include_once('../../library/config.php');

    $logadmin = new ADMIN();

    if(!$logadmin->logincheck()){
        header('location:../adminn/login/');
    }
    
    $db = new DB();
    $db->connect();
    
    if(isset($_POST['add']))
    {
        $create_date = jstrftime('%Y/%m/%e - %H:%M');
        $name = $_POST['name'];
        $data=array("name"=>"'$name'","create_date"=>"'$create_date'");
        $db->insert("email_list",$data);
    }

    
?>

<!DOCTYPE html>

<html>

<head>
        <?php
            include_once($_SERVER['DOCUMENT_ROOT'].SITE.'/library/head.php');               
        ?>
    <script>
        $(function(){
          $("div.holder").jPages({
            containerID : "container",
            perPage:8
              });
            });
    </script>
</head>

<body>

<!-- Base Table -->

<table class="body" cellspacing="0" cellpadding="0" align="center">

    <!-- Head -->

    <?php

        include($_SERVER['DOCUMENT_ROOT'].SITE.'/library/header.php');

    ?>

<tr>

    <!-- Main -->
    <td align="center" >
    <div id="main" align="center" class="ui-corner-all , ui-widget-content">
        <div align="left" style="padding: 5px;"> <a href="login/logout.php"> LOGOUT </a> </div>
        <?php
            echo $_SESSION['admin_name'];
        ?>
        پنل پیامک
        <hr />
    <!-- Top Menu -->
    <?php
        include($_SERVER['DOCUMENT_ROOT'].SITE.'/adminn/library/topmenu.php');
    ?>
    <br />
    <table dir="rtl" border="0"  cellpadding="6" cellspacing="0" style="width: 900px;">

    <tr>

        <td colspan="3">
        <form method="post" action="">
            <table style="width: 100%;">
            <tr>
                <td>
                عنوان : <input type="text" name="name" style="width: 300px;" />
                <input type="submit" value="ثبت" name="add" />
                </td>
            </tr>
            </table>
        </form>
        </td>

    </tr>

    <tr>
        <td style="width: 20px;background: #C8E0E4;"> ردیف </td>
        <td style="width: 350px;background: #C8E0E4;"> عنوان </td>
        <td style="width: 350px;background: #C8E0E4;"> عملیات </td>
        <td style="background: #C8E0E4;"> تاریخ </td>
    </tr>

    <tbody id="container">

    <?php

        $res = $db->select("email_list","","id_email_list desc");
        $i=0;
        while(isset($res[$i]['id_email_list']) && $res[$i]['id_email_list'])
        {
            print"<tr><td style='border-bottom: 1px solid #A1C4C8;'>".($i+1)."</td>";
            print"<td style='border-bottom: 1px solid #A1C4C8;' >".$res[$i]['name']."</td>";
            print"<td style='border-bottom: 1px solid #A1C4C8;' >";
            print'
            <form method="post" action=""   enctype="multipart/form-data">
            <input type="file" name="infile" />
            <input type="hidden" name="id" value="'.$res[$i]['id_email_list'].'" />
            <input type="submit" value="آپلود" name="upload" class="btn" />
            </form>
            ';
            print"</td>";
            print"<td style='border-bottom: 1px solid #A1C4C8;' dir='ltr' >".$res[$i]['create_date']."</td>";
            print"</tr>";
            $i++;
        }

        

    ?>

    </tbody>

    </table>
<?php
    if(isset($_POST['upload']))
    {
        $id = $_POST['id'];

    $file = $_FILES['infile']['tmp_name']; 
    $handle = fopen($file,"r"); 
     $cnt=0;
    //loop through the csv file and insert into database 
    do { 
        if ($data[0]) { 
  
            $A=addslashes($data[0]);
            $A = substr($A,0,-1);
            $A = substr($A,0,-1);
            $B=addslashes($data[1]);
            $where = "email='$A'";
            $res = $db->select("email",$where);
            if(count($res)>0)
            {
                $data=array("opened"=>"$B");
                $db->update("email",$data,$where);
                $cnt++;
            }
            else
            {
                $data=array("email"=>"'$A'","opened"=>"$B","email_list_id"=>"$id");
                $db->insert("email",$data);
                $cnt++;
            }
            
        } 
    } while ($data = fgetcsv($handle,1000,",","'")); 
        
        
        print"
        <script>
        alert('".$cnt."');
        </script>
        ";
    }
?>
    <div dir="ltr" class="holder"></div>
    </div>
    </td>
</tr>
<!-- Footer -->
        <?php
            include($_SERVER['DOCUMENT_ROOT'].SITE.'/library/footer.php');
        ?>

</table>

</body>

</html>