[PHP] Parse XML

2004-05-25 Thread Phil Dowson
Hi,

I am having a couple of difficulties with a script to parse XML. This may
well be because my 16 month kid was up all night, but I'm banging my head
against a wall right now.

The script quite easily extracts one of the entries listed under DATA_2
but doesnt list the other. This is my first look into parsing XML, so I am
not sure of the terminology :-). How can I have both entries in this XML
file parsed to an array that I can use to build a table. (I just really need
the array, I can take it from there).

Thanks !

Phil

Here's my code (please let me know if I'm missing anything really simple):


== PHP CODE

?
 $data = file_get_contents('db_list.xml');
 $ret = array();
 $hash_stack = array();

 $parser = xml_parser_create();
 xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
 xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,1);
 xml_parse_into_struct($parser,$data,$values,$tags);
 xml_parser_free($parser);


 foreach ($values as $key = $val) {

   if($val['type'] == open) {
 array_push($hash_stack, $val['tag']);
 }
   elseif($val['type'] == close) {
 array_pop($hash_stack);
 }
   elseif($val['type'] == complete) {
 array_push($hash_stack, $val['tag']);
 eval(\$ret[ . implode($hash_stack, ][) . ] =
'{$val[value]}';);
 array_pop($hash_stack);
 }

  }
print_r($ret);
?


== XML CODE


?xml version=1.0?
DATA_DB
  LIST_2
DATA_2
  DB_KEY09011234/DB_KEY
  LIST_1
G_1
  NAMEBLOGGS, JOE/NAME
   LIST_15
DATA_15
  ADDRESS15 MAIN STREET/ADDRESS
  CITY_STATEMAINLAND  WS/CITY_STATE
  ZIP9/ZIP
/DATA_15
  /LIST_15
/G_1
  /LIST_1
/DATA_2
DATA_2
  DB_KEY09011235/DB_KEY
  LIST_1
G_1
  NAMEBROOK, CURTIS/NAME
  LIST_15
DATA_15
  ADDRESS16 MAIN STREET/ADDRESS
  CITY_STATEMAINLAND  WS/CITY_STATE
  ZIP9/ZIP
/DATA_15
  /LIST_15
/G_1
  /LIST_1
/DATA_2
  /LIST_2
/DATA_DB

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] OTP: Programming

2004-03-07 Thread Phil Dowson
Hi,

I have been working with PHP for a few years now, and I feel very 
comfortable with it. I am considering branching out into windows 
application development, and I was wondering what language people would 
recommend for someone comfortable with PHP.

I have heard that PHP can be used in this capacity, would PHP work for 
me to create applications with a GUI?

I am sorry if this really is an off topic post!

Thanks

Phil Dowson

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP LDAP query - need to add Exchange fields

2003-12-22 Thread Phil Dowson
Ben,

I was trying the same thing, but I am not sure you are using the same 
setup as me. My office runs a windows 2000 domain with a Exchange server 
2000 box. All profile information is stored in the windows 2000 domain 
controller, and the exchange server accesses the information from there. 
So it doesnt use its own LDAP. And to make it all the more interesting, 
this script is running on our Intranet, on a FreeBSD 5 box with the 
OpenLDAP client.

The following script will bring back all the fields available in LDAP, 
as long as they are filled out. In this script you need to have a valid 
DOMAIN_USER and a valid DOMAIN_PASS. There are ways to do this 
anonymously, you just need to change the $ldap_bind line to remove the 
$ldaprdn and $ldappass.

To change the search criteria, you can change the $filter variable, at 
the moment it filters on the domain user's userid, or samaccountname.

At the bottom of this post, I have included search results based on my 
user, I have removed everything except the fields you might want.

?
$ldapuser = DOMAIN_USER;
$ldappass = DOMAIN_PASS;
$ldaprdn  = 'DOMAIN\\'.$ldapuser;
$ldapconn = @ldap_connect(dns.domain.com, 3268);
@ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
if ($ldapconn) {
$ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappass);
}
$base_dn = DC=dns,DC=domain,DC=com;
$filter=samaccountname=$ldapuser;
$read = ldap_search($ldapconn, $base_dn, $filter);
$info = ldap_get_entries($ldapconn, $read);
$ii=0;
for ($i=0; $ii$info[$i][count]; $ii++){
$data = $info[$i][$ii];
echo $data.:nbsp;nbsp;.$info[$i][$data][0].br;
}
?
Hope it helps

Phil Dowson

Ben Crothers wrote:
Hoping this is an easy question to answer, apologise upfront if this is so
basic, but just been put in charge of a PHP app with LDAP interface to M$
Exchange, and trying to figure out how it works.
At the moment it works fine and extracts fields like first- and surname,
title, department, etc. I need to add the 'office' field, and added it at
the end of this filter line:
---
 $filter =
(|(sn=$search[$i]*)(givenname=$search[$i]*)(title=$search[$i]*)(department=
$search[$i]*)(office=$search[$i]*));

...but so far it's not working. I *know* there's data in the 'office'
field -- any ideas as to what I'm missing?
Thanks a lot in advance,

Ben

---Field List---

homemdb:
manager:
memberof:
altrecipientbl:
publicdelegatesbl:
streetaddress:
info:
cn:
company:
c:
department:
description:
displayname:
mail:
facsimiletelephonenumber:
givenname:
initials:
instancetype:
legacyexchangedn:
l:
distinguishedname:
objectcategory:
objectclass:
objectguid:
objectsid:
homephone:
mobile:
pager:
physicaldeliveryofficename:
postofficebox:
postalcode:
primarygroupid:
proxyaddresses:
name:
samaccountname:
samaccounttype:
showinaddressbook:
st:
sn:
telephonenumber:
co:
textencodedoraddress:
title:
useraccountcontrol:
userprincipalname:
usnchanged:
usncreated:
whenchanged:
whencreated:
wwwhomepage:
mailnickname:
msexchuseraccountcontrol:
deliverandredirect:
homemta:
msexchhomeservername:
msexchmailboxguid:
msexchmailboxsecuritydescriptor:
mdbusedefaults:
protocolsettings:

---Field List---

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Slow LDAP Queries

2003-12-16 Thread Phil Dowson
Hi,

I am using ldap_bind to connect to an Active Directory server to
authenticate users on a website. Although the script is running,
occasionally, and at random, the process to authenticate the user will take
almost exactly 75 seconds (within 100ths of a second). Other times the
authentication process will take less than a second.

Is there any way to see what is causing the delay, does anyone know which
logs I should be looking at. The webserver is a FreeBSD box, and the Domain
controller is a Windows 2000 box.

PHP Version: 4.3.4
Apache Version: 1.3.29
FreeBSD: 5.1
Open LDAP: openldap-client-2.0.27

My code is below.

?
$ldapuser = username;
$ldappass = password;

//Script Time Debug -- START
   $mtime = microtime();
   $mtime = explode( ,$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $starttime = $mtime;
//Script Time Debug -- START

$ldaprdn  = 'DOMAINNAME\\'.$ldapuser;
$ldapconn = @ldap_connect(dns.domain.com, 3268);
@ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

if ($ldapconn) {
 $ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappass);
 if ($ldapbind) {echo you are logged in;}
 else {echo you are not logged in;}
 ldap_close($ldapconn);
 }

//Script Time Debug -- END
   $mtime = microtime();
   $mtime = explode( ,$mtime);
   $mtime = $mtime[1] + $mtime[0];
   $endtime = $mtime;
   $totaltime = ($endtime - $starttime);
   echo (script type='text/javascript'alert('$totaltime')/script);
//Script Time Debug -- END
?

Thanks

Phil Dowson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] ldap_modify(): Modify: Server is unwilling to perform

2003-12-11 Thread Phil Dowson
Hi,

I am trying to write a script that will allow users within the Windows 2000
Active Directory to be able to change thier personal details on an intranet
website. I have included the script I am using below.

The first part of the script commented as Search Script works flawlessly,
even though $base_dn is not set. The problem I am having is with the Modify
Script, when I try and modify a field it returns with the error:

Warning: ldap_modify(): Modify: Server is unwilling to perform in change.php
on line xx

Is there something in AD that stops ldap_modify? Is my problem with the
unset $base_dn? I had left the $base_dn blank, as I had no idea what it
should be. I would appreciate any help, comments or suggestions.

Thanks!

Phil Dowson

\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ Script Below \/ \/ \/
\/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/

?
$base_dn = '';
$ldappass = 'mypassword';
$ldaprdn  = 'AD\\'.$ldapuser;
$ldapconn = @ldap_connect(ad.domain.com, 3268);

//Search Script Start

@ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

if ($ldapconn) {
$ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappass);
}

$filter=samaccountname=$ldapuser;
$justthese = array(samaccountname,  info);
$read = ldap_search($ldapconn, $base_dn, $filter, $justthese);
$info = ldap_get_entries($ldapconn, $read);

//Search Script End


//Modify Script Start

$info = $_POST[info];

@ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
@ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);

if ($ldapconn) {
$ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappass);
}

$newinfo[notes][0]=$notes;
ldap_modify($ldapconn, $base_dn, $newinfo);

//Modify Script End
?

/\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ Script Above /\ /\ /\
/\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\ /\

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How many Mondays in a month?

2003-09-29 Thread Phil Dowson
Hi,

I have posted a similar question in php.db, but I was wondering if someone
could help out with a non-db issue. I am trying to display statistics of
visitors to my web site, and what I would like to do is show the average
number of visitors that have visited the site in a given month for a certain
day e.g..:

Stats for www.mysite.com for 09/2003

Monday - 15 average - 65 total
Tuesday - 16 average - 66 total
Wednesday - 14 average - 65 total
Thursday - 13 average - 63 total
Friday - 15 average - 65 total
Saturday - 5 average - 25 total
Sunday - 6 average - 28 total

I have tried a number of ways to do this, but I cannot work out a way to
show the number for example Mondays that will be in a given month, which I
need to work out the average. I can work out the total easy enough, just not
the average.

TIA

Phil Dowson

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How many Mondays in a month?

2003-09-29 Thread Phil Dowson
Greg,

That worked brilliantly... I bow down to your sheer excellence!!! Thankyou
Thankyou Thankyou



Greg Wiley [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
Funny you should ask this because I've been meaning to share some code that
I wrote a few months ago that does exactly this for any day of the week.

Please feel free to use this and make changes. I'd appreciate any
changes/bug fixes being sent back to me though.

?php
/*
 * num_days
 *
 * A function that takes a day, a month and a year and returns the number of
 * occurrences of that day in the given month and year.
 *
 * Arguments:
 * day - the day required
 * month - which month are we talking about
 * year - which year are we talking about
 *
 * Returns:
 * occ - the number of times the day occurs in the month.
 * or NULL if there are invalid parameters.
 */
function num_days ($day, $month, $year)
{
$day_array = array(Mon = Monday,
   Tue = Tuesday,
   Wed = Wednesday,
   Thu = Thursday,
   Fri = Friday,
   Sat = Saturday,
   Sun = Sunday);

$month_array = array(1 = Jan, Feb, Mar, Apr, May, Jun,
 Jul, Aug, Sep, Oct, Nov, Dec);

/*
* Check our arguments are valid.
*/

/*
* $day must be either a full day string or the 3 letter
abbreviation.
*/
if (!(in_array($day, $day_array) ||
array_key_exists($day, $day_array))) {
echo num_days: invalid argument. \$day must be day name or
three letter abbreviation;
return;
}

/*
* $month must be either a full month name or its 3 letter
abrreviation
*/
if (($mth = array_search(substr($month,0,3), $month_array)) = 0) {
echo num_days: invalid argument. \$month must be month name
or three letter abbreviation;
return;
}

/*
* Now fetch the previous $day of $month+1 in $year;
* this will give us the last $day of $month.
*/

/*
* Calculate the timestamp of the 01/$mth+1/$year.
*/
$time = mktime(0,0,0,$mth+1,1,$year);

$str = strtotime(last $day, $time);

/*
* Return nth day of month.
*/
$date = date(j, $str);

/*
* If the difference between $date1 and $date2 is 28 then
* there are 5 occurences of $day in $month/$year, otherwise
* there are just 4.
*/
if ($date = 28) {
return 4;
} else {
return 5;
}
}

?

The other function I have does this:

/*
 * nth_day
 *
 * A function that takes a number and a day and returns the date of
 * nth occurrence of that day in the given month and year.
 *
 * Arguments:
 * nth - the nth occurence required
 * day - the day required
 * month - which month are we talking about
 * year - which year are we talking about
 *
 * Returns:
 * date - the date on which the nth day occurs in month and year.
 * or NULL for errors.
 */

Give me a shout if anyone wants this one.

Cheers, Greg.


 -Original Message-
 From: Phil Dowson [mailto:[EMAIL PROTECTED]
 Sent: 29 September, 2003 16:22
 To: [EMAIL PROTECTED]
 Subject: [PHP] How many Mondays in a month?


 Hi,

 I have posted a similar question in php.db, but I was
 wondering if someone could help out with a non-db issue. I am
 trying to display statistics of visitors to my web site, and
 what I would like to do is show the average number of
 visitors that have visited the site in a given month for a
 certain day e.g..:

 Stats for www.mysite.com for 09/2003

 Monday - 15 average - 65 total
 Tuesday - 16 average - 66 total
 Wednesday - 14 average - 65 total
 Thursday - 13 average - 63 total
 Friday - 15 average - 65 total
 Saturday - 5 average - 25 total
 Sunday - 6 average - 28 total

 I have tried a number of ways to do this, but I cannot work
 out a way to show the number for example Mondays that will be
 in a given month, which I need to work out the average. I can
 work out the total easy enough, just not the average.

 TIA

 Phil Dowson

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] mail()

2003-07-05 Thread Phil Dowson
Perfect solution. Thanks!!!


- Original Message - 
From: Dan Anderson [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, July 05, 2003 4:30 am
Subject: Re: [PHP] mail()


   Could someone let me know if it is possible to pass a resultset of a
query
   to a single variable so it can be included as the message part of the
mail
   function?

 if I were you I would try something like...

 ?php

 $result = mysql_query($query);
 $email = NULL; // it's bad form to dot without clearing the variable
 while ($line = mysql_fetch_array($result,MYSQL_ASSOC))
 {
   $email = $email . Value 1: {$line['value_1']}\n;
   $email = $email . Value 2: {$line['value_2']}\n;
   $email = $email . Value 3: {$line['value_3']}\n;
   // ...
 }
 mail('[EMAIL PROTECTED]','subject',$email);
 ?


 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] mail()

2003-07-04 Thread Phil Dowson
Hi,

Could someone let me know if it is possible to pass a resultset of a query
to a single variable so it can be included as the message part of the mail
function?

Thanks!

Phil Dowson


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php