Link to home
Start Free TrialLog in
Avatar of lhaluska
lhaluska

asked on

Php catch usage?

I am trying to write this catch try code but have know clue how to translate between cfm to php can someone help please. Here is the code in php.
<?php
$Bhupi = 'bsingh@cup.com';
$webmaster = '<a href="mailto:lhaluska@cup.com?subject=Service Request Error">lhaluska</a>(408)285-1596';
$Foobar = false;
$SRDATESTAMP = date("MMMM D, YYYY");
$SRTIMESTAMP = time("hh:mm");
$SRDATETIMESTAMP = &$SRDATESTAMP &$SRTIMESTAMP;
$Foobar = false;
$auth = $_SERVER['AUTH_USER'];
$ntUserDomainId = str_replace('\\',':','$auth');
$Identified = false;
if ($Identified == 'false') {
try {
$ds=ldap_connect("ldap.cce.cup.com:389");
$r=ldap_bind($ds);
$sr=ldap_search($ds, "o=cup.com", 'uid='.$ntUserDomainId, explode(',', 'sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress'));
$info = ldap_get_entries($ds, $sr);
catch (Exception $e)
{ echo 'Caught exception: ',  $e->getMessage(), "\n";
try {
$ds=ldap_connect("ldap.cup.com:389");
$r=ldap_bind($ds);
$sr=ldap_search($ds, "o=cup.com", 'uid='.$ntUserDomainId, explode(',', 'sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress'));
$info = ldap_get_entries($ds, $sr);
}
}
?>

Here is the cfm code I am changing..
<cfset Bhupi = "bsingh@cup.com">

<!--- Need a var to break the loop. --->
<cfset Foobar = false>
            <cflock scope="server" type="readonly" timeout="3">
                  <cfset ntUserDomainId = "#Replace("#AUTH_USER#","\",":")#">
            </cflock>            
<cfset Identified = false>
<cflock scope="session" type="readonly" timeout="5">
      <cfif IsDefined("session.routeTo") AND Len("session.routeTo") GT 0>
            <cfset Identified = true>
      </cfif>
</cflock>

<cfif Identified is false>
      <cftry>
            <cfldap action="QUERY"
                              name="UserData"
                  attributes="sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress"
                              start="o=cup.com"
                              scope="SUBTREE"
                              filter="ntUserDomainId=#ntUserDomainId#"
                              server="ldap.cce.cup.com"
                              port="389">
            <cfcatch>
                  <cftry>
                        <cfldap action="QUERY"
                                    name="UserData"
                        attributes="sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress"
                                    start="o=cup.com"
                                    scope="SUBTREE"
                                    filter="ntUserDomainId=#ntUserDomainId#"
                                    server="ldap.cup.com"
                                    port="389">
                  <cfcatch>
                        <cfoutput>#cfcatch.Detail#  #cfcatch.Message# <br></cfoutput>
                        <cfmail from="lssstools@cup.com"
                                    to="lhaluska@cup.com"
                                    cc="lhaluska@cup.com"
                                    subject="LDAP Error on SR">
                                    #cfcatch.Detail#<br>
                                    #cfcatch.Message#<br>
                                    #ntUserDomainId#<br>
                                    #SRDATETIMESTAMP#
                        </cfmail>
                        <cfoutput>The Webmaster has been automatically notified. If you wish to add info, please do so:<br>            
                        <a href="mailto:lhaluska@cup.com?subject=LDAP error on SR">Notify Webmaster.</a></cfoutput>
                        <cfabort>
                  </cfcatch>
                  </cftry>
            </cfcatch>
            </cftry>
            <cfcookie name="EMAIL" value="#UserData.uid#" expires="30">
            <cfcookie name="PHONE" value="#UserData.telephonenumber#" expires="30">
            <cfset user = "#LCase("#ListLast("#ListFirst("#UserData.uid#")#","=")#")#">
            <cfif user IS NOT #Bhupi# AND Foobar IS false>
            <cfset user = "#LCase("#ListLast("#ListFirst("#userData.manager#")#","=")#")#">
            <cfset loopcounter = 0>
            <cfloop condition="user IS NOT #Bhupi# AND Foobar IS false">
            <cftry>
                  <cfldap action="QUERY"
                                    name="UserData2"
                        attributes="sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress"
                                    start="o=cup.com"
                                    scope="SUBTREE"
                                    filter="uid=#user#"
                                    server="ldap.cce.cup.com"
                                    port="389">
            <cfcatch>
                  <cftry>
                        <cfldap action="QUERY"
                                    name="UserData2"
                        attributes="sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress"
                                    start="o=cup.com"
                                    scope="SUBTREE"
                                    filter="uid=#user#"
                                    server="ldap.cup.com"
                                    port="389">
                  <cfcatch>
                        <cfoutput>#cfcatch.Detail#  #cfcatch.Message# <br></cfoutput>
                        <cfmail from="lssstools@cup.com"
                                    to="lhaluska@cup.com"
                                    subject="LDAP Error on SR">
                                    #ntUserDomainId#<br>
                                    #SRDATETIMESTAMP#<br>
                                    #user#<br>
                                    #cfcatch.Detail#<br>
                                    #cfcatch.Message#<br>
                        </cfmail>
                        <cfoutput>The Webmaster has been automatically notified. If you wish to add info, please do so:<br>            
                        <a href="mailto:lhaluska@cup.com?subject=LDAP error on SR">Notify Webmaster.</a></cfoutput>
                        <cfabort>
                  </cfcatch>
                  </cftry>
            </cfcatch>
            </cftry>
                  <cfset user = "#LCase("#ListLast("#ListFirst("#UserData2.manager#")#","=")#")#">
                  <cfset loopcounter = #loopcounter# + 1>
                  <cfif loopcounter GTE 7>
                        <cfset Foobar = true>
                  </cfif>
            </cfloop>
      </cfif>
      <cfif user IS Bhupi>
            <cflock timeout="1" type="exclusive" scope="session">
                  <cfset session.routeTo = "5996">
            </cflock>
      <cfelse>
            <cflock timeout="1" type="exclusive" scope="session">
                  <cfset session.routeTo = "9999">
            </cflock>
      </cfif>
</cfif>
<cfset webmaster = '<a href="mailto:LHaluska@cup.com?subject=service request error">LHaluska</A> (888) 888-1234'>
<cfset SRDATESTAMP = #DateFormat("#now()#", "mmmm d, yyyy")#>
<cfset SRTIMESTAMP = #TimeFormat(Now(), 'HH:mm')#>      
<cfset SRDATETIMESTAMP = "#SRDATESTAMP# #SRTIMESTAMP#">
ASKER CERTIFIED SOLUTION
Avatar of Stacy Spear
Stacy Spear
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lhaluska
lhaluska

ASKER

Hi darkstar3d,
I started coding the new page but am getting an error for my IF statement can you take a look at this code please.
Here is the error.
Parse error: syntax error, unexpected T_IF in \ServiceRequest\allpage.php on line 51
Here is the new code.I will mark line 51 with >>>>>>>>>>>>>
<?php
$to      = 'LHaluska@cup.com';
$subject = 'LDAP Error on SR';
$message = '$e->getMessage() \n
                  $ntUserDomainId \n
                  $SRDATETIMESTAMP';
$headers = 'From: lssstools@cup.com';

mail($to, $subject, $message, $headers);
$life=time()+7776000;//lives 3 months
$Bhupi = 'bingh@cup.com';
$webmaster = '<a href="mailto:lhaluska@cup.com?subject=Service Request Error">LHaluska</a>(555)555-5555';
$Foobar = false;
$SRDATESTAMP = date("MMMM D, YYYY");
$SRTIMESTAMP = time("hh:mm");
$SRDATETIMESTAMP = &$SRDATESTAMP &$SRTIMESTAMP;
$Foobar = false;
$auth = $_SERVER['AUTH_USER'];
$ntUserDomainId = str_replace('\\',':','$auth');
$Identified = false;

if ($Identified == 'false') {
      try {
            $ds=ldap_connect("ldap.cce.cup.com:389");
            $r=ldap_bind($ds);
            $sr=ldap_search($ds, "o=cup.com", 'uid='.$ntUserDomainId, explode(',', 'sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress'));
            $info = ldap_get_entries($ds, $sr);}
            catch (Exception $e){ echo 'Caught exception: ',  $e->getMessage(), "\n";

                  try {
            $ds=ldap_connect("ldap.cup.com:389");
            $r=ldap_bind($ds);
            $sr=ldap_search($ds, "o=cup.com", 'uid='.$ntUserDomainId, explode(',', 'sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress'));
            $info = ldap_get_entries($ds, $sr);
                  
setcookie("EMAIL", $info["uid"], $life, "/", "webres.qweb.cupcorp.net");
setcookie("PHONE", $info["telephonenumber"],$life, "/",  "webres.qweb.cupcorp.net");
                  }
                  catch (Exception $e) {
                        echo 'Caught exception: ',  $e->getMessage(), "\n";
                        mail ($to, $subject, $message, $headers);
                        }
                        echo ('The Webmaster has been automatically notified. If you wish to add info, please do so:<br>            
                        <a href="mailto:LHaluska@cup.com?subject=LDAP error on SR">Notify Webmaster.</a>');


            $user = strtolower($info['uid']);
            if ($user !== $Bhupi AND Foobar == false) {
            $user = strtolower($info['manager']);}
            $loopcounter = 0
>>>>>>>>>>>>      if ($user !== $Bhupi AND Foobar == false) {
                  try {
                      $ds=ldap_connect("ldap.cce.cup.com:389");
                  $r=ldap_bind($ds);
                  $sr=ldap_search($ds, "o=cup.com", 'uid='.$user, explode(',', 'sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress'));
                  $UserData2 = ldap_get_entries($ds, $sr);
                    }
            catch (Exception $e) {
                        echo 'Caught exception: ',  $e->getMessage(), "\n";
                  try {
            $ds=ldap_connect("ldap.cup.com:389");
            $r=ldap_bind($ds);
            $sr=ldap_search($ds, "o=cup.com", 'uid='.$user, explode(',', 'sn,givenname,telephonenumber,manager,ntUserDomainId,cupJobTitle,ou,uid,EMPLOYEENUMBER,managerEMPLOYEENUMBER,cn,mailRoutingAddress'));
            $UserData2 = ldap_get_entries($ds, $sr);
                  catch (Exception $e) {
                        echo 'Caught exception: ',  $e->getMessage(), "\n";
                        mail ($to, $subject, $message, $headers);
                        }
                        echo ('The Webmaster has been automatically notified. If you wish to add info, please do so:<br>            
                        <a href="mailto:LHaluska@cup.com?subject=LDAP error on SR">Notify Webmaster.</a>');
                        
                  }
                  }
            }
            }
                  $user = ('#LCase("#ListLast("#ListFirst("#UserData2.manager#")#","=")#")#')
                  $loopcounter = '#loopcounter# + 1'
                  if ($loopcounter GTE 7)
                        $Foobar = true
                  }
            }
      }
}
?>