Site d'annonces ب codeigniter الجزء الخامس


فهاد الجزء الخامس والأخير من Site d'annonces ب codeigniter غادي نكملو الملفات لي بقاو ولي غادي تكون فيهم الفورم لي كتمكن الأدمن من إضافة أدمن خور بالإضافة للملف  لي غادي يمكن الأدمن من عرض les annonces ول users منبعد غادي نشوفو الملف الرئيسي لي غادي يكون هو الصفحة الرئيسية ديالنا.

نظرة سريعة بالفيديو

1- الملف admins/add-admin.php

ف dossier views كنزيد dossier جديد كنسميه admins فيه كانزيد ملف جديد كنسميه add-admin.php فيه الكود لي كيمكن الأدمن من إضافة admin جديد فكيدخل المعلومات الخاصة به فل form ثم كترسل لل fonction store لي كاينة فل controller Admin.php الكود ديال الملف هو :


                                <?php $this->load->view('layouts/header');
if(!$this->session->userdata('admin')){
    redirect(base_url());
}
?>
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
        <?php echo validation_errors('<div class="alert alert-danger">','</div>');?>
            <div class="panel panel-default">
                <h4 class="panel-heading text-default" style="padding:10px;margin-top:-1px;">Ajouter un admin</h4>
                <div class="row" style="padding:10px;">
                    <div class="col-md-8 col-md-offset-2">
                        <form action="<?php echo base_url();?>admin/store" method="post">
                            <div class="form-group">
                                <label for="name">Nom*</label>
                                <input type="text" name="nom" class="form-control" placeholder="Nom">
                            </div>
                            <div class="form-group">
                                <label for="prenom">Prenom*</label>
                                <input type="text" name="prenom" class="form-control" placeholder="Prénom">
                            </div>
                            <div class="form-group">
                                <label for="email">Email*</label>
                                <input type="email" name="email" class="form-control" placeholder="Email">
                            </div>
                            <div class="form-group">
                                <label for="password">Mot de passe*</label>
                                <input type="password" name="password" class="form-control" placeholder="Passe">
                            </div>
                            <div class="form-group">
                                <label for="city">Ville*</label>
                                <input type="text" name="city" class="form-control" placeholder="Ville">
                            </div>
                            <div class="form-group">
                                <label for="tel">Téléphone*</label>
                                <input type="tel" name="tel" class="form-control" placeholder="Tél">
                            </div>
                            <div class="form-group">
                                <input type="submit" class="btn btn-default" name="submit" value="Valider">
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('layouts/footer');?>
                            

2- الملف admins/admin.php

دائما ف admins فيه كانزيد ملف جديد كنسميه admin.php فيه الكود لي كيمكن من عرض les annonces ول users ول admins لي عندنا فقاعدة البيانات ولي كيمكن الأدمن من مسح les annonces لي بغى ول users وأيضا les admins الكود ديال الملف هو :

                                <?php 
if(!$this->session->userdata('admin')){
    redirect(base_url());
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Admin Panel</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<?php echo base_url();?>assets/css/bootstrap.min.css">
  <link rel="stylesheet" href="<?php echo base_url();?>assets/css/custom.css"> 
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <link href="http://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet">
</head>
<body>
  <nav class="navbar navbar-default navbar-fixed-top container-fluid" role="navigation">
      <div class="container">
          <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
                  <span class="sr-only">Toggle navigation</span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
              </button>
                <a class="navbar-brand">
                   Admin
                </a>
          </div>
     </div>
 </nav>
<div class="container padded">
    <ol class="breadcrumb">
        <li><a href="<?php echo base_url();?>"><i class="icon icon-home icon-dark"></i> Voir le site</a></li>
        <li><i class="fa fa-list"></i> Tableau de bord</li>
    </ol>
</div>
<div class="container">
    <div class="row">
        <div class="col-md-24">
			<div class="">
				<div class="tabbable-line">
					<ul class="nav nav-tabs ">
						<li class="active">
							<a href="#tab_default_1" data-toggle="tab">Utilisateurs <span class="badge badge-info"><?php echo count($users);?></span></a>
						</li>
						<li>
							<a href="#tab_default_2" data-toggle="tab">Annonces <span class="badge badge-info"><?php echo count($annonces);?></span></a>
                        </li>
                        <li>
							<a href="#tab_default_3" data-toggle="tab">Admins <span class="badge badge-info"><?php echo count($admins);?></span></a>
						</li>
					</ul>
					<div class="tab-content">
						<div class="tab-pane active" id="tab_default_1">
							 <div class="container">
                                <h2>Liste des utilisateurs</h2>
                                <br/>
                                <table border="0" width="100%" cellpadding="0" cellspacing="0"  class="table table-striped table-bordered myTable">
                                    <thead>
                                        <tr>
                                            <th>Nom</th>
                                            <th>Prénom</th>
                                            <th>Email</th>
                                            <th>Ville</th>
                                            <th>Tél</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach($users as $row):?>
                                          <tr id="domain<?php echo $row->id;?>">
                                            <td><?php echo $row->firstname;?></td>
                                            <td><?php echo $row->lastname;?></td>
                                            <td><?php echo $row->email;?></td>
                                            <td><?php echo $row->city;?></td>
                                             <td><?php echo $row->Tel;?></td>
                                            <td class="options-width">
                                                 <a class="btn btn-sm btn-danger" href="<?php echo base_url();?>user/delete/<?php echo $row->id;?>"><i class="fa fa-trash"></i> Supprimer</a>
                                            </td>
                                          </tr>
                                        <?php endforeach;?>
                                    </tbody>
                                </table>
                            </div>
						</div>
						<div class="tab-pane" id="tab_default_2">
							 <div class="container">
                                <h2>Liste des annonces</h2>
                                <br/>
                                <table border="0" width="100%" cellpadding="0" cellspacing="0"  class="table table-striped table-bordered  myTable">
                                    <thead>
                                        <tr>
                                            <th>Titre</th>
                                            <th>Description</th>
                                            <th>Ville</th>
                                            <th>Photo</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach($annonces as $row):?>
                                          <tr id="domain<?php echo $row->id;?>">
                                            <td><?php echo $row->title;?></td>
                                            <td><?php echo $row->body;?></td>
                                            <td><?php echo $row->city;?></td>
                                             <td><img src="<?php echo base_url();?>assets/uploads/<?php echo $row->image;?>" height="50" width="50"></td>
                                            <td class="options-width">
                                                 <a class="btn btn-sm btn-danger" href="<?php echo base_url();?>ads/delete/<?php echo $row->id;?>"><i class="fa fa-trash"></i> Supprimer</a>
                                            </td>
                                          </tr>
                                        <?php endforeach;?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab_default_3">
							<div class="container">
                                <h2>Liste des admins</h2>
                                <br/>
                                <table border="0" width="100%" cellpadding="0" cellspacing="0"  class="table table-striped table-bordered myTable">
                                    <thead>
                                        <tr>
                                            <th>Nom</th>
                                            <th>Prénom</th>
                                            <th>Email</th>
                                            <th>Ville</th>
                                            <th>Tél</th>
                                            <th>Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach($admins as $row):?>
                                          <tr id="domain<?php echo $row->id;?>">
                                            <td><?php echo $row->firstname;?></td>
                                            <td><?php echo $row->lastname;?></td>
                                            <td><?php echo $row->email;?></td>
                                            <td><?php echo $row->city;?></td>
                                             <td><?php echo $row->Tel;?></td>
                                            <td class="options-width">
                                                <a class="btn btn-sm btn-primary" href="<?php echo base_url();?>admin/add"><i class="fa fa-user-plus"></i> Ajouter</a> <a class="btn btn-sm btn-danger" href="<?php echo base_url();?>user/delete/<?php echo $row->id;?>"><i class="fa fa-trash"></i> Supprimer</a>
                                            </td>
                                          </tr>
                                        <?php endforeach;?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
			</div>
		</div>
	</div>
</div>
<?php $this->load->view('layouts/footer');?>
                            

3- الملف includes/header.php

ف dossier views كنزيد dossier جديد كنسميه includes فيه كانزيد 2 ملفات جداد كنسميهم header.php  فيه الكود لي فيه ال menu لي كتمكن من التنقل بين الصفحات وfooter.php لي فيه les fichiers js لي كنحتاجو الكود ديال الملفات هو :

                                //header.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="<?php echo base_url();?>assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="<?php echo base_url();?>assets/css/custom.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Annonces.com</title>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="<?php echo base_url();?>">Annonces.com</a>
    </div>
    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav">
            <li class="active"><a href="<?php echo base_url();?>"><i class="fa fa-home"></i> Accueil <span class="sr-only"></span></a></li>
            <?php if($this->session->userdata('logged')):?>
            <ul class="nav navbar-nav">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <span class="fa fa-user"></span> 
                        Compte
                        <span class="fa fa-chevron-down"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li>
                            <div class="navbar-login">
                                <div class="row">
                                    <div class="col-sm-4 col-sm-offset-1 col-xs-8">
                                        <p class="text-center">
                                            <img src="<?php echo base_url()."assets/uploads/".$this->session->userdata("photo");?>" class="profileImg" height="100" width="100">
                                        </p>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-8 col-sm-offset-1  col-xs-4">
                                        <p class="text-center">
                                            <?php echo $this->session->userdata("nom")." ".$this->session->userdata("prenom");?>
                                        </p>
                                        <p class="text-center small"><?php echo $this->session->userdata("email");?></p>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li class="divider"></li>
                            <li>
                                <div class="navbar-login navbar-login-session">
                                    <div class="row">
                                        <div class="col-lg-24 col-sm-24  col-xs-12">
                                            <p>
                                                <a href="<?php echo base_url()?>user/logout" class="btn btn-danger btn-block">Déconnexion</a>
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </li>
                </ul>
            <?php else:?>
                <li><a itemprop="url" href="<?php echo base_url();?>user/register"  title="Inscription"><i class="fa fa-users"> Inscription</i></a></li>
                <li><a itemprop="url" href="<?php echo base_url();?>user/login"  title="Connexion"><i class="fa fa-lock"> Connexion</i></a></li>
            <?php endif;?>
            <li><a href="<?php echo base_url();?>ads/add"><i class="fa fa-pencil"> Déposer une annonce</i></a></li>
            <li><a href="#"><i class="fa fa-envelope"></i> Contact</a></li>
            <?php if($this->session->userdata('admin')):?>
                <li><a href="<?php echo base_url();?>admin"><i class="fa fa-dashboard"></i> Admin</a></li>
            <?php endif;?>
        </ul>
        <form class="navbar-form navbar-right" method="post" action="<?php echo base_url();?>ads/find">
            <div class="form-group">
                <input type="text" name="search" class="form-control" placeholder="Recherche">
            </div>
            <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
        </form>
     </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

//footer.php

                   </div>
               </div>
           </div>
        </div>
     </div>
  </div> <!-- /container -->
  <footer>
      <p class="text-center">DarijaCoding ©2017</p>
  </footer>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="<?php echo base_url();?>assets/js/bootstrap.min.js"></script>
  <script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
  </body>
</html>
                            

4- الملف home.php

دائما ف dossier views كنزيد ملف جديد كنسميه index.php  فيه  الكود لي كيعرض les annonces وles categories و les villes وفيه les annonces لي كيجيوني من ل fonction index لي كاينة فال controller Home الكود ديال الملف هو :

                                    <?php 
$this->load->view('layouts/header');
function tokenTruncate($string, $your_desired_width) {
    $parts = preg_split('/([\s\n\r]+)/', $string, null, PREG_SPLIT_DELIM_CAPTURE);
    $parts_count = count($parts);
    $length = 0;
    $last_part = 0;
    for (; $last_part < $parts_count; ++$last_part) {
        $length += strlen($parts[$last_part]);
        if ($length > $your_desired_width) { break; }
    }
    return implode(array_slice($parts, 0, $last_part));
} 
?>
<div class="container">
    <div class="jumbotron">
        <div class="row">
            <form action="<?php echo base_url();?>ads/find" method="post">
                <div class="col-md-3">
                    <input type="text" name="search" placeholder="Que Cherchez Vous?" class="form-control">
                </div>
                <div class="col-md-4">
                    <select  name="cat" class="form-control">
                        <option selected disabled>Veuillez choisir une catégorie</option>
                        <option value="Informatique & Téchnologie">Informatique</option>
                        <option value="Immobilier">Immobilier</option>
                        <option value="Emplois">Emplois</option>
                        <option value="Animaux">Animaux</option>
                        <option value="Vente Divers">Vente Divers</option>
                        <option value="Véhicules">Véhicules</option>
                    </select>
                </div>
                <div class="col-md-4">
                    <select  name="city" class="form-control">
                        <option selected disabled>Veuillez choisir une ville</option>
                        <option value="Casablanca">Casablanca</option>
                        <option value="Rabat">Rabat</option>
                        <option value="Fes">Fes</option>
                        <option value="Taza">Taza</option>
                        <option value="Agadir">Agadir</option>
                        <option value="Tanger">Tanger</option>
                        <option value="Oujda">Oujda</option>
                        <option value="Meknés">Meknés</option>
                    </select>
                </div>
                <div class="col-md-1">
                    <button type="submit" name="submit" class="btn btn-success"><i class="fa fa-search"></i></button>
                </div>
            </form>
        </div>
    </div>
    <div class="row">
        <div class="col-md-8">
            <div class="panel">
                <h3 class="text-default" style="padding:10px;">Choisissez une catégorie</h3>
                <hr>
                <div class="row" style="padding:10px;">
                    <div class="col-sm-4 col-md-4">
                        <div class="thumbnail">
                            <img src="<?php echo base_url();?>assets/uploads/informatiques.jpg" alt="...">
                            <div class="caption" align="center">
                                <p><a href="<?php echo base_url();?>ads/category/Informatique" class="btn btn-link" role="button">Informatiques</a></p>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4 col-md-4">
                        <div class="thumbnail">
                            <img src="<?php echo base_url();?>assets/uploads/immobilier.jpg" alt="...">
                            <div class="caption" align="center">
                                <p><a href="<?php echo base_url();?>ads/category/Immobilier" class="btn btn-link" role="button">Immobilier</a></p>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4 col-md-4">
                        <div class="thumbnail"> 
                            <img src="<?php echo base_url();?>assets/uploads/emplois.jpg" alt="...">
                            <div class="caption" align="center">
                                <p><a href="<?php echo base_url();?>ads/category/Emplois" class="btn btn-link" role="button">Emplois</a></p>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4 col-md-4">
                        <div class="thumbnail">
                            <img src="<?php echo base_url();?>assets/uploads/ventes.jpg" alt="...">
                            <div class="caption" align="center">
                                <p><a href="<?php echo base_url();?>ads/category/Vente Divers" class="btn btn-link" role="button">Vente Divers</a></p>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4 col-md-4">
                        <div class="thumbnail">
                            <img src="<?php echo base_url();?>assets/uploads/animaux.jpg" alt="...">
                            <div class="caption" align="center">
                                <p><a href="<?php echo base_url();?>ads/category/Animaux" class="btn btn-link" role="button">Animaux</a></p>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-4 col-md-4">
                        <div class="thumbnail">
                            <img src="<?php echo base_url();?>assets/uploads/vehicules.jpg" alt="...">
                            <div class="caption" align="center">
                                <p><a href="<?php echo base_url();?>ads/category/Véhicules" class="btn btn-link" role="button">Véhicules</a></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <h3 class="text-default">Choisissez une ville</h3>
            <hr>
            <ul class="list-group">
                <li class="list-group-item">
                    <a href="<?php echo base_url();?>ads/city/Casablanca" class="text-info"><i class="fa fa-chevron-right"></i> Casablanca</a>
                </li>
                <li class="list-group-item">
                    <a href="<?php echo base_url();?>ads/city/Rabat" class="text-info"><i class="fa fa-chevron-right"></i> Rabat</a></li>
                <li class="list-group-item">
                    <a href="<?php echo base_url();?>ads/city/Fes" class="text-info"><i class="fa fa-chevron-right"></i> Fes</a>
                </li>
                <li class="list-group-item">
                    <a href="<?php echo base_url();?>ads/city/Méknes" class="text-info"><i class="fa fa-chevron-right"></i> Méknes</a>
                </li>
                <li class="list-group-item">
                    <a href="<?php echo base_url();?>ads/city/Tanger" class="text-info"><i class="fa fa-chevron-right"></i> Tanger</a>
                </li>
                <li class="list-group-item">
                    <a href="<?php echo base_url();?>ads/city/Taza" class="text-info"><i class="fa fa-chevron-right"></i> Taza</a>
                </li>
                <li class="list-group-item">
                    <a href="<?php echo base_url();?>ads/city/Oujda" class="text-info"><i class="fa fa-chevron-right"></i> Oujda</a>
                </li>
                <li class="list-group-item">
                    <a href="<?php echo base_url();?>ads/city/Agadir" class="text-info"><i class="fa fa-chevron-right"></i> Agadir</a>
                </li>
            </ul>
        </div>
    </div>
    <div class="container" style="margin-top:50px">
    <h3 class="text-info" style="text-transform:uppercase;font-weight:700">Les dérnieres annonces</h3>
    <hr>
    <div class="container">
        <div class="row">          
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row">
                            <?php foreach($annonces as $annonce):?>
                            <div class="col-sm-8">
                                <div class="media">
                                    <div class="media-left">
                                        <a href="<?php echo base_url();?>ads/view/<?php echo $annonce->id;?>">
                                            <img class="media-object thumbnail" width="237" src="<?php  echo base_url();?>/assets/uploads/<?php echo $annonce->image;?>" height="150" alt="...">
                                        </a>
                                    </div>
                                    <div class="media-body">
                                        <h4 class="media-heading"><?php echo $annonce->title;?></h4>
                                        <p><?php echo $annonce->body;?></p>
                                        <p><a href="<?php echo base_url();?>ads/view/<?php echo $annonce->id;?>" class="btn btn-link">Voir <i class="fa fa-arrow-right"></i></a></p>
                                    </div>
                                    <div class="media-footer" align="right">
                                        <span class="label label-success"><i class="fa fa-tag"></i><?php echo $annonce->category;?></span>
                                        <span class="label label-default"><i class="fa fa-user"></i> Belasri imad</span>
                                        <span class="label label-warning"><i class="fa fa-calendar"></i> <?php echo $annonce->created;?></span>
                                    </div>
                                </div>
                                <hr>
                            </div>
                            <?php endforeach;?>
                        </div>
                        <a href="<?php echo base_url();?>ads" class="btn btn-primary pull-right">Toutes les annonces</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $this->load->view('layouts/footer');?>
                                

5- الملف custom.css

ف dossier ديال ل projet زيد dossier جديد سميه assets فيه زيد dossier جديد سميه css فيه زيد ملف جديد سميه custom.css فيه غادي يكونوا les styles css لي غادي نحتاجو الكود ديال الملف هو :

                                    body{
    font-family: Verdana, Geneva, Tahoma, sans-serif;
}
footer{
    position: relative;
    background-color: beige;
    border-radius: 2px;
    box-shadow: 1px 0px 0px 1px #000000;
    height: 50px !important;
}
footer p{
    text-transform: uppercase;
    font-size: 14px;
    margin-top: -2px;
}
img{
    border:1px solid #000000;
}
img.profileImg{
    text-align: center;

}
.thumbnail img{
    height: 200px;
}
p a.btn-link{
    text-align: center;
    text-transform: uppercase;
    font-weight: 700;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
    transition: color .3s ease;
}
p a.btn-link:hover{
    text-decoration: none;
    color: #000;
}
                                


بحث في الموقع


إشترك للتوصل بالجديد