PHP Classes
elePHPant
Icontem

File: empty_addressbook.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Michele Brodoloni  >  LDAP Address Book  >  empty_addressbook.php  >  Download  
File: empty_addressbook.php
Role: Example script
Content type: text/plain
Description: Sample script. Deletes all the content of an addressbook.
Class: LDAP Address Book
Manage contacts stored on an LDAP server
Author: By
Last change: php-cli
Date: 7 years ago
Size: 916 bytes
 

Contents

Class file image Download
<?php
//---[ Author: Michele Brodoloni - michele@xtnet.it
//---[ Deletes all the content of the addressbook
//---[ This script is for php-cli. Use it with php -q <script_name>

   
require("ldap_addressbook.class.php");

   
$SUCCESS=0;
   
$FAILURE=0;
   
$ldap = new LDAP_addressBook("my.ldap.host","cn=admin","dc=example, dc=com","my_ldap_secret");

    if (
$ldap->connect())
    {
       
$list = $ldap->list_entries("dn");
       
$n = count($list);
        echo(
"\n");
        for (
$i=0; $i<$n; $i++)
        {
           
$dn_to_delete = $list[$i]['dn'];
            echo
"** deleting '$dn_to_delete' ... ";
            if (
$ldap->delete_entry_by_dn($dn_to_delete))
            {
                echo
"done\n";
               
$SUCCESS++;
            } else {
                echo
"ERROR\n";
               
$FAILURE++;
            }
        }
        echo
"\n";
        echo
"Total records: $n\n".
             
"Deleted: $SUCCESS\n".
             
"Errors: $FAILURE\n\n";
    } else {
        echo
$ldap->show_error()."\n";
    }
   
$ldap->disconnect();
    exit;

?>